Maksim Ivanov Maksim Ivanov - 3 months ago 8
MySQL Question

mysqli - how to fetch a row without altering the result set?

Is it possible to extract a value from mysqli_result without fetching a row i.e. without altering the result set as I need it in full later in my code?

Answer

You can also point the iterator back to the beginning. ie..

$result = $mysqli->query($query);
while($row = $result->fetch_assoc())
{
    //do stuff with the result
}
//back to the start
mysqli_data_seek($result,0);

now the pointer is returned to the beginning. mysqli_data_seek