gpt4 book ai didi

php - mysql_fetch_array/row 只取1条数据

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

问题可能很简单。

$q = "SELECT id FROM users
WHERE name LIKE '%$u%' OR active LIKE '%$u%'";
echo $q;
$u = mysql_query($q) or die("There is a server error : " . mysql_error());
$u = mysql_fetch_array($u);
print_r($u);

但它返回我

[id] => 6

当我在 Mysql Workbench 中执行查询时,它返回

6
7
8

这可能是一个棘手的问题,但我不明白为什么。谢谢:)

最佳答案

那是因为 mysql_fetch_array 只返回一行。为了获得更多行,它循环工作。

while ($row = mysql_fetch_array($u)) {
print_r($row);
}

但是,请阅读我关于使用 mysql_* 函数的评论。这个:

Welcome to Stack Overflow! Please, don't use mysql_* functions for new code. They are no longer maintained and the community has begun the deprecation process. See the red box? Instead you should learn about prepared statements and use either PDO or MySQLi. If you can't decide, this article will help to choose. If you care to learn, here is good PDO tutorial.

关于php - mysql_fetch_array/row 只取1条数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11163532/

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