問題描述
我有一個(gè)數(shù)據(jù)庫 (SQL),其中包含Staff"表,其中有兩條記錄.我需要使用 PHP 在網(wǎng)頁上顯示這些記錄的內(nèi)容.
I have a database (SQL) with the table "Staff" with two records in it. I am required to display the contents of these records on a web page using PHP.
<html>
<head>
<title>CES Staff details</title>
</head>
<body>
**code emitted**
<?php
$row = mysql_fetch_array($result) ;
$looping = 1;
$i = $row.length;
while ($looping <= $i)
{
echo $row["Name"].", Room ".$row["Room"].", Tel ".$row["Telephone"] ;
$looping++;
}
?>
</body>
</html>
我將如何正確更改 while 循環(huán),以便在頁面上顯示兩條記錄.
How would I change the while loop correctly so that it will display both records on the page.
謝謝!
推薦答案
mysql_fetch_array()
僅從數(shù)據(jù)庫中檢索一行.您需要在 while
循環(huán)中調(diào)用它來檢索所有行.$looping
增量在這里是不必要的,因?yàn)?mysql_fetch_array()
在沒有更多行可用時(shí)返回 false.
mysql_fetch_array()
only retrieves a single row from the database. You need to call it inside your while
loop to retrieve all rows. The $looping
increment is unnecessary here, since mysql_fetch_array()
returns false when no more rows are available.
while ($row = mysql_fetch_array($result))
{
echo $row["Name"].", Room ".$row["Room"].", Tel ".$row["Telephone"] ;
}
這篇關(guān)于在 MySQL 服務(wù)器上使用 PHP 進(jìn)行循環(huán)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!