Page 1 of 1

Instead While loop

Posted: Tue May 30, 2006 9:20 am
by inigonirmal
Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hai friends,
Is there any loop instead of while for the following code.

Code: Select all

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
   printf("ID: %s  Name: %s", $row[0], $row[1]);  
}
could anyone know?.. plzzz reply me back...

Nirmal
Chennai :?:
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:1. Select the correct board for your query. Take some time to read the guidelines in the sticky topic.

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue May 30, 2006 9:40 am
by feyd
don't make duplicate threads please.

Any loop control (other than foreach directly) can be used. Is there a particular reason you want a different loop?

Posted: Tue May 30, 2006 10:26 am
by Ambush Commander
I suppose he wants to fetch all the rows at once?

Posted: Tue May 30, 2006 10:29 am
by Oren
Ambush Commander wrote:I suppose he wants to fetch all the rows at once?
Then what's wrong with the while loop? :wink:

Re: Instead While loop

Posted: Tue May 30, 2006 10:46 am
by RobertGonzalez
inigonirmal wrote:Is there any loop instead of while for the following code.

Code: Select all

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
   printf("ID: %s  Name: %s", $row[0], $row[1]);  
}
Can't you just echo directly from the while loop instead of sprintf'ing?

Code: Select all

while ($row = mysql_fetch_array($result)) {
   echo "ID: {$row['db_id_field_name']}  Name: {$row['db_id_field_name']}<br />\n";  
}