I am having trouble joining two queries together these are my queries:
$sql = "SELECT SourcePath, Description, BikeCode FROM BikeImages order by bikecode";
$sql1 = "SELECT BikeCode, Manufacturer, Model, SubType, Year, FrameMaterial, Description, Gender, Type, Price, Stock FROM Bike WHERE Stock > 0";
$result = mysqli_query($con, $sql);
$result1 = mysqli_query($con, $sql1);
Help would be really appreciated, I have had a couple of ideas to join them together such as
$result = mysqli_query($sql && $sql1, $con);
But it doesn’t seem to work, Should I join the two $sql together if so how would I do that?
EDIT: The tables are related because I want to create a while loop, that displays all the information from the Bike table and then grabs the images from the BikeImages table related to each individual BikeCode.
After linking the tables together I wish to use this code to display my information:
while(list($bikecode, $manufacturer, $model, $subtype, $year, $fmaterial, $desc, $gender, $type, $price, $stock, $sourcepath, $description) = mysqli_fetch_row($result1)) {
echo "information here
}
Thanks
You should consider using a
JOINto join these two tables together. It appears thatBikeCodeexists in both tables, so you should be able to join the queries similar to this:This then allows you to return all of the data in a single result.
If you need help learning join syntax, here is a great visual explanation of joins