What are some best practices for organizing and sorting database output based on categories like "Current" and "Past" in PHP?

When organizing and sorting database output based on categories like "Current" and "Past" in PHP, one effective approach is to use a conditional statement to check the category of each item and then display them accordingly. This can be achieved by querying the database for items that fall under the specified categories and then using a loop to iterate through the results, checking each item's category and displaying them accordingly.

// Assuming $results is the array of database output containing items with category information

foreach ($results as $item) {
    if ($item['category'] == 'Current') {
        echo "Current item: " . $item['name'] . "<br>";
    } elseif ($item['category'] == 'Past') {
        echo "Past item: " . $item['name'] . "<br>";
    }
}