How can CSS be used to format and display database query results in multiple columns in PHP?
To format and display database query results in multiple columns in PHP, you can use CSS to style the layout of the results. By using CSS properties like column-count or flexbox, you can divide the query results into multiple columns for a more organized display on the webpage.
<?php
// Perform database query
$query = "SELECT * FROM table_name";
$result = mysqli_query($connection, $query);
// Display query results in multiple columns
echo '<div style="column-count: 3;">';
while($row = mysqli_fetch_assoc($result)) {
echo '<div>' . $row['column_name'] . '</div>';
}
echo '</div>';
?>
Keywords
Related Questions
- What is the best way to query a database to count the number of entries a user has, based on specific conditions like a non-zero category ID?
- What are some common mistakes made when using while loops in PHP, as seen in the code snippet provided?
- What are some best practices for preventing SQL injections when using PHP to interact with a MySQL database?