【问题标题】:Counting total number of records in database according to the ENUM values in PHP根据PHP中的ENUM值计算数据库中的记录总数
【发布时间】:2021-09-18 15:02:23
【问题描述】:

我有一个带有“pending”、“resolved”、“unresolved”这些值的 ENUM,我想显示挂起记录、已解决记录和未解决记录的总数,我该如何在 php 中做到这一点?

【问题讨论】:

    标签: php html mysql phpmyadmin


    【解决方案1】:

    你只需要执行sql查询

    $dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
    $sql = 'SELECT type, COUNT(type) as count_type FROM Table
    GROUP BY type';
    
    foreach ($dbh->query($sql) as $row) {
        echo $row['type'] . ':' . $row['count_type'];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-24
      • 1970-01-01
      • 1970-01-01
      • 2018-10-07
      • 2016-03-28
      • 1970-01-01
      相关资源
      最近更新 更多