How can I structure my query results to have a two-dimensional array for the news entries to easily loop through them?

To structure your query results into a two-dimensional array for news entries, you can fetch the results from the database and store them in an array where each entry represents a news item with its corresponding fields. This way, you can easily loop through the array to display the news entries on your website.

// Fetch news entries from the database
$query = "SELECT * FROM news";
$result = mysqli_query($connection, $query);

// Create a two-dimensional array for news entries
$newsEntries = array();
while ($row = mysqli_fetch_assoc($result)) {
    $newsEntries[] = $row;
}

// Loop through the two-dimensional array to display news entries
foreach ($newsEntries as $entry) {
    echo "<h2>{$entry['title']}</h2>";
    echo "<p>{$entry['content']}</p>";
    // Add more fields as needed
}