Re: problem with WHILE loop
| From: | Jason G. | Date: | Mon, 01 Oct 2001 02:10:28 +0000 |
| Subject: | Re: problem with WHILE loop | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-12856@lists.php.net to get a copy of this message | ||
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:
<?php
$dbResult = mysql_query("select id,title from table1");
$nRowCount = mysql_num_rows($dbResult);
for($i=0; $i<$nRowCount; $i++)
{
$aRow = mysql_fetch_array($dbResult);
$title = $list_row["title"];
echo("$title <br>\n");
}
?>
-Jason Garber
www.ionzoft.com
*************************************
I prefer mysql_fetch_object() personally...
Replace the code with this:
<?php
$dbResult = mysql_query("select id,title from table1");
$nRowCount = mysql_num_rows($dbResult);
for($i=0; $i<$nRowCount; $i++)
{
$oRow = mysql_fetch_object($dbResult);
echo("$oRow->title <br>\n");
}
?>
At 08:32 PM 9/30/2001 -0500, you wrote:
I have the following code on a page:
<?php
$list = mysql_query("select id,title from table1");
$list_row = mysql_fetch_array($list);
$title = $list_row["title"];
while($list_row) {
echo("$title <br>\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: php-db-unsubscribe@lists.php.net
For additional commands, e-mail: php-db-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net