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.
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()
orrewind()
, likeiterators
has). However, you may extendmysqli_result
class or create a decorator, that can do it.