gpt4 book ai didi

php+mysql : how to read several time results of query

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

我在我的数据库上执行查询,我需要多次读取结果。我写了这个:

$result = mysql_query("SELECT field1, field2 FROM table WHERE true");
foreach ($my_array as $current) {
//iterate over mysql resutls
while ($current_row = mysql_fetch_array($result)) {
//do something
}
}

现在,当我第一次读取查询的所有行时,我如何才能再次开始第一行以进行下一次 foreach 迭代?

最佳答案

你可以这样做

$result = mysql_query("SELECT field1, field2 FROM table WHERE true");
foreach ($my_array as $current) {
//iterate over mysql resutls
while ($current_row = mysql_fetch_array($result)) {
//do something
}
}

mysql_data_seek($result,0);

然后继续循环!!

http://in3.php.net/mysql_data_seek

关于php+mysql : how to read several time results of query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22045805/

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