How can PHP handle sorting of tables in a way that minimizes DOM manipulation and client-side processing?

When sorting tables in PHP, we can minimize DOM manipulation and client-side processing by using server-side sorting. This involves sending the sorting criteria to the server, where the data is sorted before being sent back to the client for display. This approach reduces the amount of data transferred between the client and server, improving performance.

// Example PHP code for server-side sorting of a table

// Retrieve sorting criteria from the client
$sort_column = $_GET['sort_column'];
$sort_order = $_GET['sort_order'];

// Query the database to retrieve the data
$query = "SELECT * FROM table_name ORDER BY $sort_column $sort_order";
// Execute the query and fetch the results

// Display the sorted data in the table
foreach ($results as $row) {
    echo "<tr>";
    echo "<td>" . $row['column1'] . "</td>";
    echo "<td>" . $row['column2'] . "</td>";
    // Repeat for other columns
    echo "</tr>";
}