运行结果集时的效率


Efficiency when running through a result set

当运行结果集时,与其他方法相比,这种方法的效率有多高?

for ($iCont=0; $iCont < mysql_num_rows($this->rsQuery); $iCont++)
{
      mysql_data_seek($this->rsQuery,$iCont);
      $row=mysql_fetch_assoc($this->rsQuery);
      //more things here like write row or push it to a global array
}

使用mysql_data_seek是否存在效率问题,即使它是按顺序进行的?

一开始的mysql_num_rows()怎么样?is会影响吗?

那么,有更好的方法吗?

我想要实现的是一个方法,返回一个包含所有结果集内容的关联数组,另一个方法创建一个包含数据的网格(html表)。

感谢

我不确定这是否更有效,但看起来更好

while ($row = mysql_fetch_assoc($this->rsQuery))
{
    //do your thing here
}

由于mysql_fetch_assoc返回一行,如果不再返回行,则返回null,因此一个简单的while循环就足够了:

while($row = mysql_fetch_assoc($this->rsQuery)) {
 // ...
}