gpt4 book ai didi

php - 从我的数据库中选择

转载 作者:太空宇宙 更新时间:2023-11-03 12:13:38 25 4
gpt4 key购买 nike

谁能告诉我为什么这段代码没有输出所有的表信息,只显示一个姓名和电子邮件,而表中有多个

<?
$user_result = "select * from mytable;";
$qry = mysql_query($user_result) OR die(mysql_error());
$user_array = mysql_fetch_assoc($qry);


echo "<center>";
echo "<table CELLPADDING=10 border =1 >";
echo "<tr>";
echo "<td>".$user_array['email']."</td>";
echo "<td>".$user_array['firstname']."</td>";

echo "</tr>";
echo "</table>";

mysql_close();
?>

最佳答案

(好像是我整理的,已经给出了其他答案;无论如何提交)

你需要使用循环。我在下面的示例中使用了 while 循环。

<?
$user_result = "select * from mytable;";
$qry = mysql_query($user_result) OR die(mysql_error());

echo "<center>"; // these are deprecated btw. Use CSS
echo "<table CELLPADDING=10 border =1 >";

echo "<tr> <th>Email</th> <th>Name</th></tr>"; // added as column headers

while($user_array = mysql_fetch_array($qry))
{

echo "<tr>";
echo "<td>".$user_array['email']."</td>";
echo "<td>".$user_array['firstname']."</td>";
echo "</tr>";

}

echo "</table>";
echo "</center>"; // these are deprecated btw

mysql_close();
?>

脚注:

mysql_* 函数弃用通知:

http://www.php.net/manual/en/intro.mysql.php

此扩展自 PHP 5.5.0 起已弃用,不推荐用于编写新代码,因为它将在未来被删除。相反,mysqliPDO_MySQL应该使用扩展名。另见 MySQL API Overview在选择 MySQL API 时获取更多帮助。

这些函数允许您访问 MySQL 数据库服务器。有关 MySQL 的更多信息,请访问 » http://www.mysql.com/ .

MySQL 的文档可以在 » http://dev.mysql.com/doc/ 找到.

关于php - 从我的数据库中选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23140130/

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