Skip to content
PHP Logo

How can PHP variables be further processed after a MySQL query?

After executing a MySQL query in PHP, the retrieved data can be stored in PHP variables for further processing. These variables can be manipulated, formatted, or used in calculations as needed. To do this, simply assign the query results to PHP variables and then perform any desired operations on those variables.

php
// Execute MySQL query
$query = "SELECT * FROM table_name";
$result = mysqli_query($connection, $query);

// Store query results in PHP variables
while($row = mysqli_fetch_assoc($result)) {
    $id = $row['id'];
    $name = $row['name'];
    
    // Further process variables as needed
    $formattedName = strtoupper($name);
    
    // Output or use processed variables
    echo "ID: $id, Formatted Name: $formattedName <br>";
}