How can PHP be used to display specific data from multiple tables in a news website?

To display specific data from multiple tables in a news website using PHP, you can use SQL queries to retrieve the necessary information from the tables and then display it on the webpage using PHP. You can use JOIN statements in your SQL queries to retrieve data from multiple tables based on a common column. Once you have fetched the data, you can use PHP to format and display it on the webpage.

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

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

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

// SQL query to retrieve specific data from multiple tables
$sql = "SELECT articles.title, authors.name
        FROM articles
        INNER JOIN authors ON articles.author_id = authors.id";

$result = $conn->query($sql);

// Display the data on the webpage
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "Title: " . $row["title"]. " - Author: " . $row["name"]. "<br>";
    }
} else {
    echo "0 results";
}

$conn->close();
?>