I'm having trouble using the mysqli_free_result()
function. I am nesting queries and it seems when I free the results it stops the initial query from running its loop with the while()
function. Am I using the mysqli_free_result()
improperly? If I change the name of the 2nd query from $results
to $results2
it works fine. Seems there is an issue with the variables over writting, which is where I thought mysqli_free_result()
would help but apparently not.
Here is a sample code similar to what I am trying to do.
<?php
// 1st query
$query = '';
// Run the 1st query
if( $results = mysqli_query( $db_connect, $query ) ) {
while( $result = mysqli_fetch_assoc( $results ) ) {
// 2nd query
$query = '';
// Run the 2nd query
if( $results = mysqli_query( $db_connect, $query ) ) {
while( $result = mysqli_fetch_assoc( $results ) ) {
}
mysqli_free_result( $results );
}
}
mysqli_free_result( $results );
}
?>