How can PHP be used to offer a database query for printing in landscape orientation?

To offer a database query for printing in landscape orientation using PHP, you can utilize CSS to set the page orientation to landscape. This can be achieved by creating a separate CSS file with the necessary styles and linking it in your PHP script. By setting the page orientation to landscape in the CSS, you can ensure that the database query results will be printed in landscape orientation.

<?php
// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Perform database query
$sql = "SELECT * FROM table_name";
$result = $conn->query($sql);

// Output the results in landscape orientation
echo '<link rel="stylesheet" type="text/css" href="landscape.css">';
echo '<table>';
while($row = $result->fetch_assoc()) {
    echo '<tr>';
    foreach($row as $key => $value) {
        echo '<td>' . $value . '</td>';
    }
    echo '</tr>';
}
echo '</table>';

// Close the database connection
$conn->close();
?>