Jump to content

How To Catch Results From Select Count(*)


50r

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/271122-how-to-catch-results-from-select-count/
Share on other sites

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];

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.