What are the potential performance issues with using while loops in PHP for database queries over multiple tables?

Using while loops for database queries over multiple tables can lead to performance issues due to the potential for excessive queries being executed. This can result in slower processing times and increased server load. To improve performance, it is recommended to use JOIN statements in SQL queries to retrieve data from multiple tables in a single query.

$query = "SELECT * FROM table1 
          JOIN table2 ON table1.id = table2.table1_id 
          WHERE condition = 'value'";
$result = mysqli_query($connection, $query);

while($row = mysqli_fetch_assoc($result)) {
    // Process data from the query result
}