如何在mysqli_query结果对象中返回一条记录[关闭]

I know mysqli_data_seek let us move at the desired offset, but how can I use it to go just one step back when a specific criteria met? I am using while-loop for the condition so you can conclude that when the condition will be met the pointer will be on next record. How can I pull it back just one step?

Try this:

$i = 0;
while($row = mysqli_fetch_row($result)){
 if($i != 0 && condition){
       mysqli_data_seek($result, $i-1);
 }
$i++;
}

It is not so hard as it seems.

  1. Count fetched offset.
  2. When you reach condition go to offset - 1 and iterate cycle with continue if needed.

Example:

$offset = 0;

while($row = $result->fetch_assoc()){

   if($condition && $offset){
        $result->data_seek(--$offset);
        continue;
   }

   $offset++;

   // actions

}

Also, I'll quote my comment:

There are no such build-in methods (i.e. prev(), next(), current() or rewind(), like iterators has). However, you may extend mysqli_result class or create a decorator, that can do it.