gpt4 book ai didi

php - 使用 PHP 显示表中的记录

转载 作者:行者123 更新时间:2023-11-29 23:25:45 24 4
gpt4 key购买 nike

很抱歉这个新手问题,但我正在编写我的第一个 PHP 脚本,但似乎无法使其工作。我只想显示单个 MySQL 表中的记录。我多年来一直尝试这样做,但在提取数据之前,除了前两个 echo 语句之外,它没有显示任何内容。

我做错了什么?

<?php
mysql_connect("localhost", "me", "mypass") or die(mysql_error());
echo "Connection to the server was successful!<br/>";

mysql_select_db("test") or die(mysql_error());
echo "Database was selected!<br/>";

$result = mysql_query("SELECT * FROM Customer");

while($row = mysql_fetch_assoc($result)){
echo "ID: ".$row['customer_id'].", Name:".$row['customer_name']
."<br/>";
}
?>

最佳答案

echo mysql_num_rows($result);

了解查询返回的行数。

关于php - 使用 PHP 显示表中的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26984810/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com