2016-02-09 141 views
-4
<html> 
<head><title> Inpatient Search </title><head> 
<body> 

<h1> Inpatient Search </h1> 


<?php 
$wardnumber = $_POST['wardnumber']; 


$conn = mysqli_connect("127.0.0.1","root","root",""); 
if (mysqli_connect_errno()) { 
    printf("Connect failed: %s\n", mysqli_connect_error()); 
    exit(); 
} 

if ($q1 = mysqli_query($conn,"select s.Inpatient_id, s.Ward_number,c.Room_number,c.Floor_number,c.Class 
     from joseph.ward_stay_1501003f s, joseph.ward_1501003f c 
     where s.Ward_number = c.Ward_number and s.Ward_number='$wardnumber'")) { 

    print "<table border=1>"; 

    print "<TR><TH>Inpatient id</TH><TH>Ward number</TH><TH>Room number</TH><TH>Floor number</TH><TH>Class</TH></TR>"; 

    while ($r1 = mysqli_fetch_row($q1)) { 
     for ($k=0; $k<count($r1); $k++){  
      print htmlspecialchars($r1[$k]). " : "; 
     } 
     print "<BR>"; 
    }; 

} else { 
    printf("Errormessage: %s\n", mysqli_error($conn)); 
} 

mysqli_close($conn); 

?> 
</body> 
</html> 

我有一個有序的輸出。我如何解決它,使數據頂部的表頭?PHP奇怪的輸出

+3

提示:繞過角色要求不能解決問題質量問題。 –

+0

在while循環中,你爲什麼不回顯表格行?你從一張桌子開始,然後轉向一個列表。這不是一個PHP問題。這是關於您輸出的html的問題 –

回答

0
while ($r1 = mysqli_fetch_row($q1)) { 
    print "<tr>"; //you have to initiate a table row 
    for ($k=0; $k<count($r1); $k++){  
    print "<td>"; //AND table cells. 
    print htmlspecialchars($r1[$k]). " : "; 
    print "</td>";// which to close is optional, but clean 
}  
print "</tr>"; //but BR is for text, not for tables. 
}; 

當您將數據寫入表中時,也必須使用表結構。

編輯:哦,別忘了與

print "</table>"; 

</td></tr>標籤是可選的關閉表,</table>是沒有的。