What are the potential pitfalls of running multiple queries on the same table in PHP?

Running multiple queries on the same table in PHP can lead to performance issues and potential data inconsistencies. To avoid these pitfalls, you can combine multiple queries into a single query using JOINs or subqueries. This will reduce the number of database interactions and improve the overall efficiency of your code.

// Example of combining multiple queries into a single query using JOINs

$query = "SELECT t1.column1, t2.column2 
          FROM table1 t1 
          JOIN table2 t2 
          ON t1.id = t2.id";

$result = mysqli_query($connection, $query);

if(mysqli_num_rows($result) > 0) {
    while($row = mysqli_fetch_assoc($result)) {
        // Process the results
    }
} else {
    echo "No results found";
}