Jamie Obrien Jamie Obrien - 3 months ago 52
PHP Question

running 2 SQL select statements

I am trying to run 2 SQL Select queries to retrieve data from 2 different tables and then echo the fields from both tables. The code I am trying doesn't seem to work, any help would be appreciated.

$ModelID = $_GET['model_id'];

$result = mysqli_query($con, "SELECT RegNumber, Colour FROM Car WHERE ModelID = '$ModelID'


SELECT CarModel, CarMake, CostPerDay FROM Model WHERE ModelID = '$ModelID'");

while($row = $result->fetch_assoc())
echo $row["CarModel"];
echo $row["CarMake"];
echo $row["CostPerDay"];
echo $row["RegNumber"];
echo " - " .$row["Colour"];

Fky Fky

You can change request :

SELECT c.RegNumber, c.Colour , m.CarModel, m.CarMake, m.CostPerDay FROM Car c INNER JOIN Model m ON m.ModelID=c.ModelID WHERE c.ModelID = '$ModelID'