50r Posted November 24, 2012 Share Posted November 24, 2012 Hello freaks this has got me trying to figure out how to get the number of row using the select conunt() but i cant figure it out. here is the code $sql = mysql_query("SELECT COUNT(*) FROM tbl_menu WHERE module = $id"); if(!$sql){echo "there is an error".mysql_error();} I just want to catch the number of row as a result. Quote Link to comment https://forums.phpfreaks.com/topic/271122-how-to-catch-results-from-select-count/ Share on other sites More sharing options...
Pikachu2000 Posted November 24, 2012 Share Posted November 24, 2012 You do it just like any other SELECT query, by using mysql_fetch_[array|assoc|row]() on the result resource. Quote Link to comment https://forums.phpfreaks.com/topic/271122-how-to-catch-results-from-select-count/#findComment-1394820 Share on other sites More sharing options...
Psycho Posted November 24, 2012 Share Posted November 24, 2012 That query (assuming it doesn't fail) will return a singe record with a single element whcih is the number of rows that match your condition. So you just need to get the value from that first record. You can use the "normal" mysql_fetch function or you can use mysql_result() $row_count = mysql_result($sql, 0); $row = mysql_fetch_array($sql); $row_count =$row[0]; Quote Link to comment https://forums.phpfreaks.com/topic/271122-how-to-catch-results-from-select-count/#findComment-1394821 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.