note 94276 added to function.mysql-result

From: Date: Mon, 26 Oct 2009 20:13:31 +0000
Subject: note 94276 added to function.mysql-result
Groups: php.notes 
Request: Send a blank email to php-notes+get-162129@lists.php.net to get a copy of this message
I hope someone can help me with this question. I have 2 code snippets. The first works, the second doesn't. I would prefer using the second code snippet because it seems cleaner. What's wrong with the second code snippet? This works; $results = mysql_query("SELECT DISTINCT(col) FROM table WHERE col != '' ORDER BY RAND()"); for( $i = 0; $i < mysql_num_rows( $results ); $i++ ) { // do something with mysql_result($results,$i,0); } This doesn't work; $results = mysql_query("SELECT DISTINCT(col) FROM table WHERE col != '' ORDER BY RAND()"); if(mysql_num_rows($results) > 0) { while($result = mysql_fetch_array($results)) { //dp something with $result } } ---- Server IP: 213.249.64.162 Probable Submitter: 62.194.130.60 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-result.php Edit -- https://master.php.net/note/edit/94276 Del: integrated -- https://master.php.net/note/delete/94276/integrated Del: useless -- https://master.php.net/note/delete/94276/useless Del: bad code -- https://master.php.net/note/delete/94276/bad+code Del: spam -- https://master.php.net/note/delete/94276/spam Del: non-english -- https://master.php.net/note/delete/94276/non-english Del: in docs -- https://master.php.net/note/delete/94276/in+docs Del: other reasons-- https://master.php.net/note/delete/94276 Reject -- https://master.php.net/note/reject/94276 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#162129) next »