gpt4 book ai didi

php - mysql_fetch_array() 无法正常工作,缺少大多数值

转载 作者:行者123 更新时间:2023-11-29 05:32:55 24 4
gpt4 key购买 nike

好吧,我正在尝试从 mysql 表中获取键值数组,而 mysql_fetch_array() 似乎无法正常工作。代码:

                        $x="select id from topics"
$set=mysql_query($x);
echo mysql_num_rows($set);
print_r(mysql_fetch_array($set));
$ids=mysql_fetch_array($set);
echo $ids[0];
echo $ids[1];

我已经移动了所有东西,但似乎没有任何改变输出:

66//结果集中值的个数

Array ( [0] => 3 [id] => 3 )//值(单数)被移动到数组

4//假设上述数组的单个值

我真的不确定这里发生了什么......

最佳答案

mysql_fetch_array 将单行返回为 PHP 数组,按列名和基于 0 的索引进行索引。它不会将整个集合加载到一个巨大的数组中,这似乎是您所期望的。

您必须在循环中迭代结果集,如下所示:

$x="select id from topics";
$set = mysql_query($x);
echo mysql_num_rows($set);
$giant_list_of_ids = array();
while ($row = mysql_fetch_array($set))
{
echo $row[0]; //or alternatively, echo $row['id'];
$giant_list_of_ids[] = $row[0];
}

关于php - mysql_fetch_array() 无法正常工作,缺少大多数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13243486/

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