2015-08-28 43 views
0

這裏是數據庫的樣子 enter image description here顯示整個表可選空字段

所以我想喜歡

Champion name 
name of the column e.g. Q name of the spell - Surging Tides 
the rest of spells for that champion 
Next Champion etc., 

這顯示它是我現在顯示冠軍名的方式

$champions = $conn->prepare("SELECT * 
          FROM champions 
          Where Patch_No = ?"); 
$champions->bind_param('s', $Patch_No); 
$champions->execute(); 
$champions_result = $champions->get_result(); 

while($row = $champions_result->fetch_assoc()){ 
    echo $row['Champion'].' '.$row['NumNotNull'].'<br>';  
} 

我真的不能相信一個簡單的方法與可能出現的問題最少的做到這一點。

下面是另一個例子應該怎麼看起來像

enter image description here

+0

你爲什麼不使用HTML表? – Barmar

+0

@Barmar你通過HTML表格的意思,我只是不知道如何正確地獲取所有信息,以顯示它像我發現去年imgur – Higeath

+0

不'SELECT *'獲取所有的信息? – Barmar

回答

1

$row是一個關聯數組,這樣你就可以循環通過它與foreach並測試該列是否爲空。

while($row = $champions_result->fetch_assoc()){ 
    echo $row['Champion'].' '.$row['NumNotNull'].'<br>'; 
    foreach ($row as $column_name => $column) { 
     if ($column_name == 'Champion' || $column_name == 'NumNotNull') { 
      continue; // These fields were already displayed above 
     } 
     if (!empty($column)) { 
      echo "$column_name $column<br>"; 
     } 
    } 
}