How can you use the "order by" function in PHP to sort data in descending order?
To sort data in descending order using the "order by" function in PHP, you can simply add "DESC" after the column name in the SQL query. This will instruct the database to sort the data in descending order based on that column.
$query = "SELECT * FROM table_name ORDER BY column_name DESC";
$result = mysqli_query($connection, $query);
// Fetch and display the sorted data
while($row = mysqli_fetch_assoc($result)) {
echo $row['column_name'] . "<br>";
}
Keywords
Related Questions
- How can one ensure that PHP code is placed in the appropriate forum category based on the level of expertise required to address the issue?
- What steps can be taken in PHP to ensure that session data is properly destroyed and that users cannot access protected areas after logging out?
- What are the best practices for handling file uploads in PHP to avoid timeouts or errors?