When using the ORDER BY clause in SQL with PHP, how can you specify the sorting order as descending?
When using the ORDER BY clause in SQL with PHP, you can specify the sorting order as descending by adding the keyword "DESC" after the column name you are sorting by. This will sort the results in descending order rather than the default ascending order.
$query = "SELECT * FROM table_name ORDER BY column_name DESC";
$result = mysqli_query($connection, $query);
// Fetch and display the results
while ($row = mysqli_fetch_assoc($result)) {
echo $row['column_name'] . "<br>";
}
Keywords
Related Questions
- What security considerations should be taken into account when sending emails through PHP scripts?
- How can PHP developers ensure that their code is secure and protected from SQL injection attacks when updating database records?
- Can Perl scripts be executed from within a PHP program, and if so, what are the best practices for doing so?