Instead While loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
inigonirmal
Forum Newbie
Posts: 2
Joined: Tue May 30, 2006 8:32 am

Instead While loop

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

I suppose he wants to fetch all the rows at once?
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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:
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Instead While loop

Post 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";  
}
Post Reply