PHP:从 MySQL 列输出数据
我想获取给定列中的所有行并输出它们,但我的代码不起作用:
$result = mysql_query("SELECT Name,Number FROM Users WHERE Customer_ID = 1);
if (!$result) {
die("Query to show fields from table failed");
}
$row = mysql_fetch_assoc($result);
echo $row['Name'];
echo $row['Number'];
^ This code is only displaying the first row, how can I list all the rows?
I wanted to get all the rows in a given column and output them, but my code is just not working:
$result = mysql_query("SELECT Name,Number FROM Users WHERE Customer_ID = 1);
if (!$result) {
die("Query to show fields from table failed");
}
$row = mysql_fetch_assoc($result);
echo $row['Name'];
echo $row['Number'];
^ This code is only displaying the first row, how can I list all the rows?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须循环遍历各行。获取 mysql_fetch_assoc 1 次,只会返回 1 行(第一行),因此您必须为结果中的每一行执行 mysql_fetch_assoc 。像这样的事情会做:
You have to loop through the rows. Getting the
mysql_fetch_assoc
1 time, will only return you 1 row (the first one), so you have to do amysql_fetch_assoc
for each row in the result. Something like this would do:为了显示所有行,您需要使用“while”循环,如下所示:
希望这有帮助。
In order to display all the rows, you need to use 'while' loop as following:
Hope this helps.