2015-08-23 16 views
0

我有mysql輸出到表的問題。腳本完美地工作,我得到的數據是我需要的,但表中的列是混亂的。似乎這些回聲可能存在問題,但我嘗試了所有可能的組合,但是我發現/想出了所有可能的組合,到目前爲止沒有任何工作。帶引導的PHP/MySQL輸出到表中 - 列被混淆了

if (mysqli_num_rows($result) > 0) { 
    while($row = mysqli_fetch_assoc($result)) { 
     echo"<table class='table table-hover table-striped table-responsive'>"; 
     echo"<tr class='table_row'>"; 
     echo"<td>" . $row['1'] . "</td>"; 
     echo"<td>" . $row['2'] . "</td>"; 
     echo"<td>" . $row['3'] . "</td>"; 
     echo"<td>" . $row['4'] . "</td>"; 
     echo"<td><a href='#'><button type='button' class='btn btn-danger btn-xs glyphicon glyphicon-remove-circle'></button></a></td>"; 
     echo"</tr>"; 
     echo"</table>"; 
    } 
} 

回答

0

你必須嘗試這個辦法:

if (mysqli_num_rows($result) > 0) { 
    echo"<table class='table table-hover table-striped table-responsive'>"; 
        while($row = mysqli_fetch_assoc($result)) { 

        echo"<tr class='table_row'>"; 
        echo"<td>" . $row['1'] . "</td>"; 
        echo"<td>" . $row['2'] . "</td>"; 
        echo"<td>" . $row['3'] . "</td>"; 
        echo"<td>" . $row['4'] . "</td>"; 
        echo"<td><a href='#'><button type='button' class='btn btn-danger btn-xs glyphicon glyphicon-remove-circle'></button></a></td>"; 
        echo"</tr>"; 

        } 
echo"</table>"; 
} 

您正在重複while循環中的表。希望這對你有所幫助。