Jump to content

Help with count()


Darkmatter5

Recommended Posts

Here's my code

$query="SELECT folder_id FROM folders WHERE cabinet_id=2";
$result=mysql_query($query) or die ($query. '<br>' .mysql_error());
$count=count(mysql_fetch_array($result));
echo $count;

 

Here's my table example:

TABLE - folders

folder_id: 1

cabinet_id: 2

 

folder_id: 2

cabinet_id: 1

 

The result I'm getting from "echo $count" is 2, why isn't it 1?  Do I have to always subtract 1 from $count before I echo it or something?

Link to comment
https://forums.phpfreaks.com/topic/127602-help-with-count/
Share on other sites

mysql_fetch_array — Fetch a result row as an associative array, a numeric array, or both

 

That's why. Use mysql_num_rows() instead:

 

$query="SELECT folder_id FROM folders WHERE cabinet_id=2";
$result=mysql_query($query) or die ($query. '<br>' .mysql_error());
$count=mysql_num_rows($result);
echo $count;

Link to comment
https://forums.phpfreaks.com/topic/127602-help-with-count/#findComment-660225
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.