gpt4 book ai didi

php - MySQL/PHP - 获取不同的行

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

好吧,我有一个数据库,每个数据库都有一个 ID、一个名称和一个文本值。

我希望能够单独打印每一行。当我使用

$result = mysql_query("SELECT * FROM mytable", $db);
$row = mysql_fetch_array($result);
echo $row['text'];

我只能打印第一行,因为它没有选择任何细节。问题是,我不确定如何使用 WHERE ID='X',因为我希望第一个打印第一列,第二个打印第二列等等(总共有 13 行).我想在页面的不同位置回显它们,所以一次调用所有内容并不是我想要的。

现在的情况是,每次打印时我都必须使用上面的代码,并在第一次打印时手动编辑 WHERE ID='1',第二次打印时手动编辑 WHERE ID='2 ' 等等,这是相当痛苦的事情。

如有任何建议,我们将不胜感激。

最佳答案

继续调用 mysql_fetch_array 直到它返回 null:

while($row = mysql_fetch_array($result ))
{
echo $row['text'] . '<br/>';
}

这显示在 documentation 中,它还会告诉您:

Warning This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:

关于php - MySQL/PHP - 获取不同的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28572022/

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