note 3330 deleted from mysql_fetch_array by danbeck

From: Date: Thu, 07 Sep 2000 15:34:19 +0000
Subject: note 3330 deleted from mysql_fetch_array by danbeck
Groups: php.notes 
Request: Send a blank email to php-notes+get-4379@lists.php.net to get a copy of this message
This screwed me up: Since fields with NULL values do not set array elements in a fetch_array(), if ALL of the fields in a row are NULL, no elements get set in the array, and thus the following while loop will end prematurely: <pre> $q = mysql_query("select field from table"); while ($row = mysql_fetch_array($q)) [do something...] </pre> This loop ends when it hits the first field==NULL, not when it gets to the end of the result set. Apparently the truth test on an array returns false for an empty array. e.g: <pre> if (array()) // this evaluates to false dosomething; </pre>

« previous php.notes (#4379) next »