How can the ORDER BY clause be used to sort data first by one column and then by another column in a MySQL query using PHP?
To sort data first by one column and then by another column in a MySQL query using PHP, you can use the ORDER BY clause with multiple columns specified in the desired order. This allows you to sort the data based on the first column and then further sort it based on the second column if there are any ties. Simply list the columns in the ORDER BY clause separated by commas to achieve this.
$query = "SELECT * FROM table_name ORDER BY column1, column2";
$result = mysqli_query($connection, $query);
if(mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
// Process the retrieved data
}
} else {
echo "No results found.";
}