Skip to content
PHP Logo

What is the purpose of the Newsscript mentioned in the forum thread?

The purpose of the Newsscript mentioned in the forum thread is to display news articles on a website. The issue being discussed is that the Newsscript is not properly displaying the articles in the desired format. To solve this issue, the code snippet below can be used to properly format and display the news articles:

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

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

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

// Retrieve news articles from database
$sql = "SELECT * FROM news_articles";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // Output data of each row
    while($row = $result->fetch_assoc()) {
        echo "Title: " . $row["title"]. "<br>";
        echo "Author: " . $row["author"]. "<br>";
        echo "Content: " . $row["content"]. "<br><br>";
    }
} else {
    echo "0 results";
}

$conn->close();
?>