Darkmatter5 Posted October 8, 2008 Share Posted October 8, 2008 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 More sharing options...
F1Fan Posted October 8, 2008 Share Posted October 8, 2008 Are you just trying to count the number of columns your query is returning? Assign your mysql_fetch_array() to a variable, then count it and print_r() it and tell us what you get. Link to comment https://forums.phpfreaks.com/topic/127602-help-with-count/#findComment-660223 Share on other sites More sharing options...
thebadbad Posted October 8, 2008 Share Posted October 8, 2008 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 More sharing options...
Darkmatter5 Posted October 8, 2008 Author Share Posted October 8, 2008 Worked, thanks! Link to comment https://forums.phpfreaks.com/topic/127602-help-with-count/#findComment-660239 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.