I faced a similar issue when trying to use the output of MySQL results as a dictionary to get titles based on id.
As mysqli_result acts as a pointer to mysqli_query
output stored somewhere in the server, means that once it's fetched it's no longer found it returns NULL
when trying to access it again (multiple iterations or another). One way I was able to overcome it was by fetching the mysqli_result
to a JSON array
which allowed for it to act as a dictionary (iterate through it infinite time).
$result = mysqli_query($con, $query);
while($row = mysqli_fetch_assoc($result )) {
$results_clone[] = $row ;
}
Now you shall be able to use/access $results_clone
infinite times. Sample code:
for($i=0;$i<count($results_clone);$i++){
$results_clone[$i];
}