[ILUG] fetch_row problem

Michael Armbrecht marmbrecht at eircom.net
Sun Mar 28 00:11:21 GMT 2004


Am Samstag, 27. März 2004 23:00 schrieb nils:


> can anyone see anything wrong with this.
> $result = mysql_query("SELECT topic_id, forum_id, topic_last_post_id,
> topic_title, topic_poster, topic_views, topic_replies,topic_moved_id
> FROM phpbb_topics ORDER BY topic_last_post_id DESC");
>
> This should put the return array into each var listed.

Am I correct in assuming that the language you are talking about is actually 
PHP?

> while(list($topic_id, $forum_id, $topic_last_post_id, $topic_title,
> $topic_poster, $topic_views, $topic_replies, $topic_moved_id) =
> mysql_fetch_row($result));
>
> but when i do echo $topic_id, i get no value returned.

Which is no surprise, really, because the body of the while loop is empty.
Your while loop keeps looping until the list() function returns false, which 
is at the end of your result set, and in this case there are no more rows to 
be retrieved, so your variables don't contain anything. 

> but if i change the the while  for this i get back
> $myrow = mysql_fetch_row($result);
> echo "<pre>";
> print_r($myrow);
> echo "</pre>";
> I get this back
>
> Array
> (
>     [0] => 26
>     [1] => 12
>     [2] => 65
>     [3] => vega strike
>     [4] => 6
>     [5] => 1
>     [6] => 0
>     [7] => 0
> )

Yes, but this time you don't loop, but print out the first result row.

Try
     while(list($topic_id, $forum_id, $topic_last_post_id, $topic_title,
     $topic_poster, $topic_views, $topic_replies, $topic_moved_id) =
     mysql_fetch_row($result)) {
	   echo $topic_id;
    }
instead. This should print out a list of topic_id, assuming that your query 
actually returns at least one row.

Mick
-- 
War is peace.  Freedom is slavery.  Ketchup is a vegetable.




More information about the ILUG mailing list