Jump to content

How To Catch Results From Select Count(*)


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.