RE: [PHP-DB] problem with WHILE loop
$list = mysql_query("select id,title from table1"); while ($row = mysql_fetch_array($list)) { echo("$row[title]\n"); } -Original Message- From: Eric J Schwinder [mailto:[EMAIL PROTECTED]] Sent: den 1 oktober 2001 20:18 To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] problem with WHILE loop Thanks to everyone who replied either here or via e-mail... I got a lot of great suggestions. I ended up solving the WHILE problem by changing this: > $list = mysql_query("select id,title from table1"); > $list_row = mysql_fetch_array($list); > $title = $list_row["title"]; > while($list_row) { > echo("$title \n"); > } to this: $list = mysql_query("select id,title from table1"); $title = $list_row["title"]; while($list_row = mysql_fetch_array($list)) { echo("$title \n"); } Eric Schwinder eric.AT.bergencomputing.DOT.com AT = @ DOT = (well... you know) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] problem with WHILE loop
Thanks to everyone who replied either here or via e-mail... I got a lot of great suggestions. I ended up solving the WHILE problem by changing this: > $list = mysql_query("select id,title from table1"); > $list_row = mysql_fetch_array($list); > $title = $list_row["title"]; > while($list_row) { > echo("$title \n"); > } to this: $list = mysql_query("select id,title from table1"); $title = $list_row["title"]; while($list_row = mysql_fetch_array($list)) { echo("$title \n"); } Eric Schwinder eric.AT.bergencomputing.DOT.com AT = @ DOT = (well... you know) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] problem with WHILE loop
the mysql_query function returns a Result Identifier. For every row in the result (found by mysql_num_rows), you must call one of the the row retrieval functions (mysql_fetch_array, mysql_fetch_object, etc...) These functions automatically advance the row position in the Result. Replace the code with this: \n"); } ?> -Jason Garber www.ionzoft.com * I prefer mysql_fetch_object() personally... Replace the code with this: title \n"); } ?> At 08:32 PM 9/30/2001 -0500, you wrote: I have the following code on a page: \n"); } ?> For some reason, when I load the page, instead of a list of the titles from table1, I get the title from the first row of table1 repeated over and over. Obviously I'm doing something wrong, and it's probably something really dumb, right in front of my face... but I can't find it! help? Thanks, Eric Schwinder eric.AT.bergencomputing.DOT.com AT = @ DOT = (well... you know) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] problem with WHILE loop
I have the following code on a page: \n"); } ?> For some reason, when I load the page, instead of a list of the titles from table1, I get the title from the first row of table1 repeated over and over. Obviously I'm doing something wrong, and it's probably something really dumb, right in front of my face... but I can't find it! help? Thanks, Eric Schwinder eric.AT.bergencomputing.DOT.com AT = @ DOT = (well... you know) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]