如何两次通过mysql结果?
问题描述:
无论出于何种原因,我都需要两次通过mysql结果集.有办法吗? 我不想运行两次查询,也不需要重写脚本,以便它将行存储在某处,然后在以后重用.
For whatever reason I need to go through a mysql result set twice. Is there a way to do it? I don't want to run the query twice and I don't want to have to rewrite the script so that it stores the rows somewhere and then reuses them later.
答
这是您可以执行的操作:
This is how you can do it:
$result = mysql_query(/* Your query */);
while($row = mysql_fetch_assoc($result)){
// do whatever here...
}
// set the pointer back to the beginning
mysql_data_seek($result, 0);
while($row = mysql_fetch_assoc($result)){
// do whatever here...
}
但是,我不得不说,这似乎不是处理此问题的正确方法.为什么不在第一个循环中进行处理?
However, I would have to say, this doesn't seem the right way to handle this. Why not do the processing within the first loop?