我有一个值为1或0的已发布字段。我希望能够提醒用户有多少记录需要发布或未发布。我想从表推荐书中计算published等于0的记录数,并将该值输出为

Awaiting to be published:#with published=0

我有这个,我意识到这是错误的:

$sql = mysql_query("SELECT * FROM testimonials WHERE published='0'");
$result=mysql_num_rows($sql);
echo $result;

最佳答案

$sql = mysql_query("SELECT SUM(published=0) AS nb_unpublished,
                           SUM(published=1) AS nb_published FROM testimonials");
$result = mysql_fetch_assoc($sql);
echo "Records awaiting to be published:" . $result['nb_unpublished'] . '<br>';
echo "Records already published:" . $result['nb_published'] . '<br>';

10-07 22:36