Re: Strange bahavior with mysql_fetch_array($result)

From: Date: Fri, 21 Nov 2003 02:22:38 +0000
Subject: Re: Strange bahavior with mysql_fetch_array($result)
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-31682@lists.php.net to get a copy of this message
On Thursday 20 November 2003 08:54 pm, Evan Panagiotopoulos wrote: > I am searching a table and have the following php code with my > comments: > > $result = mysql_query($query); > print "The result == $result"; > // it returns The result == Resource id #2" > if (!mysql_fetch_array($result)) { > ... > } else { > while ($row = mysql_fetch_array($result)) { > ... > } > } Try -> $result = mysql_query($query); // Test to see if the query failed if ($result === false) { die('some meaningful message'); } // Test to see if there are results to return if (mysql_num_rows($result) > 0) { // Get results while($row = mysql_fetch_array($result)) { .... } } else { echo 'No Results'; }

« previous php.db (#31682) next »