如何使用 mysql_* 函数多次循环遍历 MySQL 结果集? [英] How can I loop through a MySQL result set more than once using the mysql_* functions?

查看:50
本文介绍了如何使用 mysql_* 函数多次循环遍历 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.

推荐答案

您可以这样做:

$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_* 函数多次循环遍历 MySQL 结果集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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