2015-08-28 40 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>"; 
     } 
    } 
}