note 94276 rejected from function.mysql-result by danbrown

From: Date: Mon, 26 Oct 2009 21:38:11 +0000
Subject: note 94276 rejected from function.mysql-result by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162132@lists.php.net to get a copy of this message
Note Submitter: theo dot lagendijk at gmail dot com ---- 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 } }

« previous php.notes (#162132) next »