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.
CES Staff details**code emitted**
$row = mysql_fetch_array($result) ;
$looping = 1;
$i = $row.length;
while ($looping <= $i)
{
echo $row["Name"].", Room ".$row["Room"].", Tel ".$row["Telephone"] ;
$looping++;
}
?>
How would I change the while loop correctly so that it will display both records on the page.
Thanks!
解决方案
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"] ;
}