How can multiple SELECT queries be written sequentially in PHP without overwriting the previous ones?

When writing multiple SELECT queries in PHP, you can store the results of each query in separate variables to prevent overwriting. This way, you can access the results of each query individually without losing the data from the previous queries.

// Connect to the database
$conn = new mysqli($servername, $username, $password, $dbname);

// Query 1
$query1 = "SELECT * FROM table1";
$result1 = $conn->query($query1);

// Query 2
$query2 = "SELECT * FROM table2";
$result2 = $conn->query($query2);

// Process results of Query 1
if ($result1->num_rows > 0) {
    while($row = $result1->fetch_assoc()) {
        // Process rows from Query 1
    }
}

// Process results of Query 2
if ($result2->num_rows > 0) {
    while($row = $result2->fetch_assoc()) {
        // Process rows from Query 2
    }
}

// Close the connection
$conn->close();