English 中文(简体)
简单地找到目前用于我的sql_fetch_assoc loop的数据点?
原标题:Simplest way to get the current location of the data pointer for mysql_fetch_assoc loop?
  • 时间:2009-10-13 18:13:08
  •  标签:

鉴于SélectT查询的一笔费用已退回了20个牢房,该评论在 lo中最简单地得出什么结论?

while ($row = mysql_fetch_assoc($result))
{
    // echo "success" when i get to the 9th row
}
最佳回答

您可使用<代码>mysql_data_seek(,以核实第9行是否存在:

if(mysql_data_seek($result, 8) !== false) {
    // success, internal pointer is now at 9
    // still need to call mysql_fetch to get the row
}

但是,在计算费用时,你可以站在内部点。 a. 使用假体保持距离:

for($i = 0; $row = mysql_fetch_assoc($result); $i++) {
    if($i == 8) // success
}
问题回答
$i=0;

while ($row = mysql_fetch_assoc($result))
{
    ++$i;
    if($i==9)
        echo "success";
}
$i = 0; // Or 1 if need be
while ($row = mysql_fetch_assoc($result))
{
    // echo "success" when i get to the 9th row
   if($i == 9) {
      echo "success";
   }
   $i++;
}

while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
  if($row[8] !=   ) {
   echo "success"; 
  }
}

while ($row = mysql_fetch_assoc($result))
{
  if($row[ column_name_of_the_ninth_field ] !=   ) {
   echo "success"; 
  }
}

其他答复中已经详细说明的方法都是这样做的有效方法。

如果你真心想做的是把内部点推向第9次结果,而不必走路,那么,这就是你可以寻求的:

if ( mysql_data_seek ($result,9) ) echo "success";




相关问题
热门标签