php while mysql,While循环使用PHP与MySQL服务器

本文介绍了如何使用PHP从SQL数据库中检索并显示多个记录。原始问题中,代码只显示了一条记录,因为mysql_fetch_array()在每次循环外只获取一行。解决方法是在while循环内调用mysql_fetch_array(),直到没有更多记录。这样可以正确显示所有记录。
摘要由CSDN通过智能技术生成

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"] ;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值