mschrank99 Posted November 9, 2006 Share Posted November 9, 2006 $result... (yadda yadda, postgresql query);$row = pg_fetch_all($result);$count = count($row);The strange thing is, $count is never = 0 when there is nothing to be found. It always returns at least a value of 1. Why is this happening?Thanks,Matt Link to comment https://forums.phpfreaks.com/topic/26641-count-function-wont-return-0-when-counting-arrays-from-the-db/ Share on other sites More sharing options...
btherl Posted November 9, 2006 Share Posted November 9, 2006 If there's nothing to be found, then $row will be set to false. The value false consists of one item, so counting it will always give you one.Instead, use[code]if ($row === false) print "Finished fetching data from database\n";[/code] Link to comment https://forums.phpfreaks.com/topic/26641-count-function-wont-return-0-when-counting-arrays-from-the-db/#findComment-121888 Share on other sites More sharing options...
mschrank99 Posted November 9, 2006 Author Share Posted November 9, 2006 Thank you very much- I used the following code:if ($family_accounts != FALSE) { $count = count($family_accounts);}else { $count = 0;} Link to comment https://forums.phpfreaks.com/topic/26641-count-function-wont-return-0-when-counting-arrays-from-the-db/#findComment-121953 Share on other sites More sharing options...
Orio Posted November 9, 2006 Share Posted November 9, 2006 If you want a shorter version:$count = (!family_accounts) ? 0 : count($family_accounts);Orio. Link to comment https://forums.phpfreaks.com/topic/26641-count-function-wont-return-0-when-counting-arrays-from-the-db/#findComment-122044 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.