本文介绍了您可以在PHP中重用mysql结果集吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从大型数据库中提取的结果集:

I have a result set I pull from a large database:

$result = mysql_query($sql);

我一次遍历此记录集以提取特定的数据位,并使用while($row = mysql_fetch_array($result))获得平均值.在页面的稍后,我想再次遍历这个相同的记录集并输出所有内容-但是由于我之前使用了记录集,因此我的第二个循环什么都不返回.

I loop through this recordset once to pull specific bits of data and get averages using while($row = mysql_fetch_array($result)). Later in the page, I want to loop through this same recordset again and output everything - but because I used the recordset earlier, my second loop returns nothing.

我终于通过遍历第二个相同的记录集($result2 = mysql_query($sql);)来解决这个问题,但是我讨厌两次进行相同的SQL调用.有什么方法可以多次遍历同一数据集吗?

I finally hacked around this by looping through a second identical recordset ($result2 = mysql_query($sql);), but I hate to make the same SQL call twice. Any way I can loop through the same dataset multiple times?

推荐答案

使用:

mysql_data_seek($result, 0);

您已经获得了免费",因为它已经被缓冲了.

You get this "free", since it's already buffered.

另外,您可以使用 mysql_unbuffered_query .

As a separate note, you can explicitly do an unbuffered query with mysql_unbuffered_query.

这篇关于您可以在PHP中重用mysql结果集吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 01:50