如何两次通过mysql结果? [英] How to go through mysql result twice?

查看:79
本文介绍了如何两次通过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?

这篇关于如何两次通过mysql结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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