使用两次查询mysql_fetch_array [英] Use query twice mysql_fetch_array

查看:62
本文介绍了使用两次查询mysql_fetch_array的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单

$stuff = mysql_query("SELECT * FROM users");

while($s = mysql_fetch_array($stuff)){
# ....
}

while($r = mysql_fetch_array($stuff)){
# ...
}

最后一个while()不起作用.我试过运行foreach($ stuff as $ s),但随后出现无效的数组错误.

The last while() does not work. I have tried run foreach($stuff as $s) but then i get invalid array error.

如何两次使用同一查询?

How can i use the same query twice?

推荐答案

$stuff = mysql_query("SELECT * FROM users");

while($s = mysql_fetch_array($stuff)){
# ....
}
// add this line
mysql_data_seek( $stuff, 0 );

while($r = mysql_fetch_array($stuff)){
# ...
}

应该做到这一点

另一种方法当然是将结果存储在数组中并重复使用

Another way is of course to store your result in an array and reuse that

这篇关于使用两次查询mysql_fetch_array的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆