----- Original Message ----- From: "Guru Geek" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, May 30, 2003 3:15 PM Subject: [PHP] array count() oddity
> Hello, > > I have a mysql statement listed below. The table contains about 100 > rows of information. Only one row matches the $criteria. Can anyone > tell me why the count($myrow) is 8? Shouldn't it be 4 (id, vanNumber, > origin, destination)? > > $criteria = "02-25-2003"; > $result = mysql_query("SELECT id, vanNumber, origin, destination FROM > thisHereTable WHERE date='$criteria'"); > $myrow = mysql_fetch_array($result); > > And when I run the rest of the script, it prints out the results 8 times > instead of once.... > for ($count=0; $count<count($myrow); $count++) > { > print "<p>".$myrow["vanNumber"]; > print "<br>".$myrow["origin"]." to ".$myrow["destination"]; > } > > THANKS, > Roger Hi, mysql_fetch_array(); produces two arrays, one indexed and one associative, thus count() will return twice the expected number. Use mysql_fetch_row() to retrieve a single indexed array or mysql_fetch_assoc() to retrieve a single associative array. Refer to the documentation: http://us2.php.net/manual/en/function.mysql-fetch-array.php - Kevin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php