homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Looping Tutorial Help (PHP)

 3:54 pm on Jun 10, 2002 (gmt 0)

Hello I am looking for a tutorial on how to loop until EOF.

I have no problem getting one row from the db with:

<?php printf(mysql_result($pResult,0,"UserID"));?>

I have tried to loop, but with no success, I did however manage to grind the server to a halt as my script produced and infinite loop :-).





 4:25 pm on Jun 10, 2002 (gmt 0)

There are a number of ways to accomplish this here's one example:

$num_rows = mysql_num_rows($result);
for ($i = 0; $i <= $num_rows; $i++) {
print mysql_fetch_array($result);


 1:42 pm on Jun 11, 2002 (gmt 0)

Here is one ukgimp its not the one I was looking for but i am not at home and dont have my bookmarks.


 3:53 pm on Jun 11, 2002 (gmt 0)

The functions mysql_fetch_row(), mysql_fetch_array() and mysql_fetch_object() return one row from the result, and then move the pointer on. If there are no more rows to fetch, it returns false. This means you can you use a very simple while loop:

$result=mysql_query("SELECT * FROM sometable");

This will automatically terminate when the last row has been processed.

The difference between mysql_fetch_row() and mysql_fetch_array() is that the first returns the results in a numeric array ($row[0], $row[1] etc), while the latter returns a the results an array containing both numeric and associative keys ($row["name"], $row["email"] etc). mysql_fetch_object() returns an object ($row->name, $row->email etc).

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved