[英]$result not usable after mysql_fetch_assoc($result), why
i get data from sql then run while ($list = mysql_fetch_assoc($result)) { ... } 我从sql获取数据然后运行($ list = mysql_fetch_assoc($ result)){...}
then i try to do the same thing but its giving nothing like result is empty does using mysql_fetch_assoc() clears $request variable? 然后我尝试做同样的事情,但它没有给出结果是空的,使用mysql_fetch_assoc()清除$ request变量?
The function keeps a counter, so of course you can't keep using it when it's gotten to the end. 该功能保留了一个计数器,所以当它到达终点时你当然不能继续使用它。 Is there a particular reason for looping through it twice? 有两次循环的特殊原因吗? Anyways: 无论如何:
mysql_data_seek($request, 0);
Is what you need before the second loop. 在第二次循环之前你需要的是什么。
You've hit the end of $result resurce using while
loop. 你已经使用while
循环结束$ result resurce了。 To solve this, rewind your pointer back to 0 position when you want to use your resource again... look at mysql_data_seek() function for more info. 要解决此问题,当您想再次使用资源时,将指针倒回到0位置...查看mysql_data_seek()函数以获取更多信息。
mysql_fetch_assoc
itself doesn't know when you are and are not calling it in a while loop. mysql_fetch_assoc
本身不知道你什么时候,并没有在while循环中调用它。 It doesn't magically reset to the start of the resultset when you use it in a separate loop. 当您在单独的循环中使用它时,它不会神奇地重置为结果集的开头。
Reset it to the start of the resultset with mysql_data_seek
once you've reached the end and want to go back to the beginning... or, ideally, remove your need to iterate the results twice. 一旦你到达终点并使用mysql_data_seek
将其重置为结果集的开头,并且想要回到开头......或者理想情况下,不需要重复两次结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.