嗨我試圖顯示從一個MySQL表中水平檢索使用PHP的HTML表中的數據。下面的代碼運行良好,除了它在我的數據庫中留下第一條記錄(從第二條記錄開始)。我確信它與櫃檯有關,但我似乎無法弄清楚如何讓它停止這樣做。如果有人能指出我的錯誤,我會非常感激!使用php和mysql水平顯示數據
$items = 5;
$query = "SELECT * FROM members ";
$result = mysql_query($query)
or die(mysql_error());
$row = mysql_fetch_array($result);
if (mysql_num_rows($result) > 0) {
echo '<table border="1">';
$i = 0;
while($row = mysql_fetch_array($result)){
$first_name = $row['first_name'];
if ($i==0) {
echo "<tr>\n";
}
echo "\t<td align=\center\">$first_name</td>\n";
$i++;
if ($i == $items) {
echo "</tr>\n";
$i = 0;
}
}//end while loop
if ($i > 0) {
for (;$i < $items; $i++) {
echo "<td> </td>\n";
}
echo '</tr>';
}//end ($i>0) if
echo '</table>';
}else {
echo 'no records found';
}
你不應該使用'mysql_'功能,和你的縮進繁瑣 – samayo