如果数据表中的计数值为空,则隐藏空td

时间:2013-07-17 17:17:21

标签: php mysql pdo html-table hide

我有这个脚本在mysql db中隐藏NULL值,但是EMPTY值总是计算它们...所以我怎么能隐藏这个值呢?

<table class="table table-bordered table-striped table-condensed bootstrap-datatable datatable" >
    <thead>
        <tr>
            <th>Diagn&oacute;sticos</th>
            <th class="center sorting_desc">Casos vistos</th>                                
        </tr>
    </thead>   
    <tbody>
        <? 
            $sql = $conn->prepare("select diagnostico, count(diagnostico) from ( select diagnostico as diagnostico from DIAGNOSTICON WHERE id_doctor = $id_doctor union all select diagnostico1 as diagnostico from DIAGNOSTICON union all select diagnostico2 as diagnostico from DIAGNOSTICON union all select diagnostico3 as diagnostico from DIAGNOSTICON) t group by t.diagnostico order by count(diagnostico) desc ");
            $sql->execute();
            while($row = $sql->fetch(PDO::FETCH_ASSOC)) {
            echo "<tr>\n";                                  
            echo "<td>";
                if (!empty($row["diagnostico"]))
            { 
            echo $row["diagnostico"]."</td>\n"; } 
            echo "<td>";
                if (!empty($row["count(diagnostico)"]))
            {
            echo $row["count(diagnostico)"]."</td>\n";
            echo "</tr>\n";  }
            }
        ?> 
    </tbody>
</table>

1 个答案:

答案 0 :(得分:0)

替换

count(diagnostico)

count(case when diagnostico = '' then NULL else diagnostico end)