Read both tables records by INNER JOIN in php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$database = "studenttwo";
// Create Connection
$conn = new mysqli($servername, $username, $password, $database);
// Check Connection
if ($conn->connect_error) {
die("Connection failed : " . $conn->connect_error);
}
Above File is mysqli_conn.php File.Below File is read.php File.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>PHP Table</title>
</head>
<body>
<table border="1px solid black" cellpadding="5px" cellspacing="2px">
<tr>
<th>CID</th>
<th>CITYNAME</th>
<th>ID</th>
<th>NAME</th>
<th>PERCENTAGE</th>
<th>AGE</th>
<th>GENDER</th>
<th>CITY</th>
</tr>
<?php
include("mysqli_conn.php");
$sql = "SELECT * FROM city INNER JOIN personal on city.cid = personal.city";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td><br>" . $row["cid"] . "</td>" . "<td>" . $row["cityname"] . "</td>" . "<td>" . $row["id"] . "</td>" . "<td>" . $row["name"] . "</td>" . "<td>" . $row["percentage"] . "</td>" . "<td>" . $row["age"] . "</td>" . "<td>" . $row["gender"] . "</td>" . "<td>" . $row["city"] . "</td>" . "<br></td>";
echo "</tr>";
}
} else {
echo "No Record Found.";
} ?>
</table>
</body>
Comments
Post a Comment