Reputation: 25
I need to retrieve the number of rows in my qrec_id
in my table tbl_link_qa
, which has values in them.
mysql_query("SELECT COUNT(qrec_id) from tbl_link_qa")or die(mysql_error());
But this doesn't seem to give any output.
----updated:
$x=0;
mysql_query("SELECT COUNT * from tbl_link_qa WHERE qrec_id != $x");
Upvotes: 0
Views: 211
Reputation: 6249
use this query instead to get number of columns with not null values:
SELECT SUM(qrec_id IS NOT NULL) FROM tbl_link_qa
or
SELECT count(*) FROM tbl_link_qa WHERE qrec_id IS NOT NULL
and @Gordon script
Upvotes: 1
Reputation: 31730
This wouldn't give any output because all it's doing is sending the query to the database. It's not actually collecting the results.
You need to assign the result of mysql_query() to a variable.
<?php
if ($result = mysql_query ('select count(*) from wherever;'))
{
$row = mysql_fetch_assoc ($result);
var_dump ($row);
}
else
die ('some error message');
?>
Upvotes: 2
Reputation: 146450
You have a full example in the manual page:
See example #2.
Upvotes: 1