I am trying to run a query to my mysql database through php and and am trying to get all the resulting rows. I also have to compare every row to the next row returned. I am trying to do this by setting the result variable to another temporary variable and calling mysqli_fetch_assoc()
on that so that the while loop runs again for the next row. But what happens is that when I try to use mysqli_fetch_assoc()
even on the other variables, somehow mysqli_fetch_assoc($result)
also progresses to the next of the next row when while($row = mysqli_fetch_assoc($result))
goes to next iteration.
Here is the code example to illustrate this :
$query = "SELECT * FROM records ORDER BY num ASC;";
if($result = mysqli_query($conn, $query))
{
while($row = mysqli_fetch_assoc($result))
{
$temporaryresult = $result;
$rowtwo = mysqli_fetch_assoc($temporaryresult);// this makes mysqli_fetch_assoc($result) skip the next row which is unwanted
}
}
So how can I keep mysqli_fetch_assoc($result)
from moving forward when I call mysqli_fetch_assoc($temporaryresult)
?
Any help would be appreciated.