$sql = "SELECT name FROM users"; $result = $db->fetchCol($sql); // Output the results foreach($result as $name) { echo $name . "
"; }
$sql = "SELECT COUNT(*) FROM orders"; $count = $db->fetchCol($sql)[0]; echo "There are " . $count . " orders in the database.";In this example, we are using the `fetchCol()` method to retrieve the number of orders in the `orders` table. Since the `fetchCol()` method returns an array, we need to access the first element using the `[0]` index in order to retrieve the count. Based on the function name and syntax, it appears that the `fetchCol()` method is part of a database library, most likely a PHP database abstraction layer like PDO or MySQLi.