2014-04-06 139 views
1

我試圖抓住我的MYSQL表格中的所有內容,然後將其全部放入表格中。出於某種原因,它將它全部放入一行中,而不是爲更多數據創建新行。我的表格沒有正確填充

我有我的代碼在這裏:

<?php 
     //DISPLAY CURRENT USERS ASC ON VIEW 
     $q="SELECT * FROM users ORDER BY id ASC"; 
     $r=mysqli_query($dbc,$q); 

     ?> 

<div class="panel panel-default"> 
    <!-- Default panel contents --> 
    <div class="panel-heading">User Manager</div> 
    <div class="panel-body"> 
    <p>Some default panel content here. Nulla vitae elit libero, a pharetra augue. Aenean lacinia bibendum nulla sed consectetur. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Nullam id dolor id nibh ultricies vehicula ut id elit.</p> 
    </div> 

    <!-- Table --> 
<div class="table-responsive"> 
      <table class="table table-striped"> 
       <thead> 
       <tr> 
        <th>UserID</th> 
        <th>First Name</th> 
        <th>Last Name</th> 
        <th>Email</th> 
        <th>Status</th> 
        <th>Role</th> 
       </tr> 
       </thead> 
       <tbody> 
       <?php echo "<tr>"; // Display Users onto table 
    while (($list= mysqli_fetch_assoc($r))){ 
      echo"<td>".$list['id']."</td>"; 
      echo"<td>".$list['fname']."</td>"; 
      echo"<td>".$list['lname']."</td>"; 
      echo"<td>".$list['email']."</td>"; 
      echo"<td>".$list['status']."</td>"; 
      echo"<td>".$list['role']."</td>"; 

    } 
       echo"</tr>";?>  

       </tbody> 
      </table> 
      </div> 

</div> 
+0

標籤(即行標籤)也應該循環。 – vanion

+0

並在環路外取出''和''。 –

+0

謝謝大家修復它。對不起,延遲已經遠離編碼了一下。感謝你的幫助! – Ready

回答

1

所有TR標籤是退出循環。

+0

doh!愚蠢的錯誤。感謝Benio,你真棒! – Ready

1

看來你需要啓動

echo "<tr>"; 

和 結束與

echo "</tr>; 

現在你正在做這個while循環中只有一次