2013-07-17 32 views
0

我有這個腳本,它在mysql db中隱藏NULL值,但是EMPTY值總是會計數它們......所以我怎樣才能隱藏這些值呢?如果數據表中的計數值爲空,則隱藏空td

<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> 

回答

0

更換

count(diagnostico) 

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

謝謝你,隱藏這些空values..I改變所有'計數(diagnostico)'你的例子和作品! –