如何在yii php标签中计算索引页中数据库空字段

r1zhe5dt  于 2022-11-09  发布在  PHP
关注(0)|答案(2)|浏览(138)

我想计算readdate,它在表中必须为空。我想用html启动代码,有一个表,它包含像id,storeid,message,readdate,entrydate这样的字段。如果readdate为空,那么我想计算它并显示这些计数。

<html>
   <div class="orange-count">
      <?php
         echo $unread_recommendation = Storenotification::model()->count("id='" . Yii::app()->session['id'] . "' AND readdate='null' ");
       ?>
   </div>
</html>
t3psigkw

t3psigkw1#

空计数的Sql命令

select count(*) from table where column IS NULL;

根据您的框架进行更改。

r7s23pms

r7s23pms2#

试试看:

$count = Storenotification::model()->countByAttributes(array(
                'id'=>Yii::app()->session['id'],
                'readdate' => ""
));
echo $count;

这应该也能用,不过我还没有测试过:

$count = Storenotification::model()->countByAttributes(array("id"=>Yii::app()->session['id']), "readdate IS NULL OR readdate = ''");

相关问题