<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>
我有一个有序的输出。如何修复它以使标题表位于数据之上?
答案 0 :(得分: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>
不是。