开发者

MYSQL : help with count row function

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");


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');
?>


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


You have a full example in the manual page:

http://es.php.net/mysql_query

See example #2.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜