I have got two tables in MySQL database, I want to use php to search in them, which I am able to do. however the problem is coming when I want to display data from table in my website. Those two tables have different field names and different number of fields. Is there any possibility to display rows by index or something like that. thanks a lot for your help.
That's my code php code:
<?php
//variables to connect to db
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "project";
$lookingto = $_POST["sendTo"];
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//getting user details from data base
$sql = "SELECT * FROM ".$lookingto."";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table><tr><th>Your search results</th></tr>";
echo "<tr><td><h3>Name</h3></td><td><h3>ID</h3></td></tr><tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<td>".$row["make"]."</td><td>".$row["model"]."</td></tr>";
}
echo "</table>";
} else {
echo $lookingto;
echo "No details found, please check your details and try again";
}
$conn->close();
?>