$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database_name";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM users
LEFT JOIN posts ON users.id = posts.user_id";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$user_id = $row['id'];
$user_name = $row['name'];
$post_id = $row['post_id'];
$post_title = $row['title'];
}
} else {
echo "No data found.";
}
$conn->close();