简体   繁体   English

在mysql_fetch_assoc($ result)之后$ result不可用,为什么

[英]$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.

相关问题 mysql_fetch_assoc仅返回1个结果 - mysql_fetch_assoc only returns 1 result 一起使用mysql_fetch_assoc和mysql_result吗? - Using mysql_fetch_assoc and mysql_result together? PHP函数“ mysql_fetch_Assoc”的错误结果 - Wrong result with PHP function 'mysql_fetch_Assoc' 如何在mysql_fetch_assoc结果中传递post变量 - how to pass a post variable in mysql_fetch_assoc result while($ row = mysql_fetch_assoc($ result)) - 如何预测$ row? - while($row = mysql_fetch_assoc($result)) - How to foreach $row? (警告:mysql_fetch_assoc():提供的参数不是有效的MySQL结果资源),除了查询返回数据外 - (Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource) except the query returns data PHP MYSQL如何查找mysql_fetch_assoc中是否存在变量及其在数组中的位置,然后将结果设置为变量 - PHP MYSQL How to find if a variable exists in mysql_fetch_assoc and its position in the array then set result as variables 获取警告“mysql_fetch_assoc():提供的参数不是有效的MySQL结果资源” - Getting warning “mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource” mysql_fetch_assoc()的结果将旧值合并为新值。 有任何想法吗? - The result from mysql_fetch_assoc() compounds old values onto new values. Any ideas? mysql_fetch_assoc问题 - Problem with mysql_fetch_assoc
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM