Current location: Hot Scripts Forums » Programming Languages » PHP » While loop


While loop

Reply
  #1 (permalink)  
Old 11-22-04, 02:55 PM
jaishalg jaishalg is offline
Newbie Coder
 
Join Date: May 2004
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy While loop

Hey all... i m facing a problem in while loop
anyone can help me plz. a little help will solve my problem

anyways i m doing this...
$first=mysql_query("select * from weeklymaster where nameofrsmzsm='$name'");
while ($row = mysql_fetch_object($first))
{
$nextid=$row->asmrsmid;
$nextid=$nextid;
echo("<br>Next ID ----".$nextid);
}
this is prints all the values of Next ID.but now i want those all values r in while loop out side the while loop. means...

$first=mysql_query("select * from weeklymaster where nameofrsmzsm='$name'");
while ($row = mysql_fetch_object($first))
{
$nextid=$row->asmrsmid;
$nextid=$nextid;
echo("<br>Next ID ----".$nextid);
}
echo("<br>Next ID ----".$nextid);

this is prints the last value of the nextid......


HOW CAN I GET ALL THE 4 VALUES WHICH WAS THERE IN WHILE LOOP OUTSIDE THE WHILE LOOP

HELP ME PLZ
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-23-04, 04:36 PM
vek vek is offline
Newbie Coder
 
Join Date: Oct 2004
Location: Florence, Ky
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

$a_nextid = array();// create the array

$first mysql_query("select * from weeklymaster where nameofrsmzsm='$name'");
while (
$row mysql_fetch_object($first))
{
   
$nextid $row->asmrsmid;
   
$a_nextid[] = $nextid// same as array_push($a_nextid, $nextid);
   
echo('<br>Next ID ----'.$nextid);
}
// will print exactly the same thing as the while loop in order
foreach($a_nextid as $id)  // $id is the value that was pushed into the array
{
   echo(
'<br>Next ID ----'.$id); // use single quotes unless the string needs parsed.  could also do echo("<br>Next ID ----$id");

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
loop function and increase numbers nassau PHP 43 10-13-04 10:50 AM
How to do SQL query in a ASP while loop superman2004 ASP 2 09-09-04 04:35 AM
Loop - Convert number into day of the week dihan PHP 12 06-30-04 05:28 AM
SQL infinite loop problem with VB application Syed Visual Basic 2 05-07-04 11:19 AM
type mismatch and update loop - HELP! seala ASP 1 09-22-03 06:27 PM


All times are GMT -5. The time now is 06:33 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.