The main table is CAR
table that looks like this:
The next table is a MODEL
table that looks like
The other table that I'm dealing with is called BODY_TYPE
and it looks like this
The last table that I'm dealing with is called MAKE
and it looks as illustrated in the following image
Now what I'm looking to achieve is to fetch MODEL
that matches BODY_TYPE
and the MAKE
and must be available on the CAR
table.
Basically, CAR
contains all cars, so the data that I'm supposed to fetch must be in CAR
. If a model is not available on the car table then it should not be shown.
this is my code but it keeps returning empty results. Not sure where am going wrong. I have tried for hours with no success
function fetch_model_options( $boody_type, $make ){
$conbd = Conectar_two();
$Query = "select mo.model from CAR c, MODEL mo, MAKE m , BODY_TYPE bo
WHERE mo.id_model = c.id_model and
c.id_make = m.id_make AND
(
( mo.id_body_type = bo.id_body_type AND bo.body_type LIKE '%$boody_type%' AND c.id_body_type = bo.id_body_type )
AND
( mo.id_make = m.id_make AND m.make LIKE '%$make%' )
)
AND
c.available =1
group by m.id_make";
if ($Result = $conbd->query($Query)){
echo "There are some results\n";
while($reg = $Result->fetch_array(MYSQLI_BOTH)){
echo '<option value="'.$reg['model']. '">'.$reg['model']. '</option>' . "\n";
//printf("<select class='form-control'>" ,$reg["body_type"]);
//$tmp = "<select class='form-control' id='".$reg["body_type"]."'>";
//echo("<option value='' id='".$reg["body_type"]."'>");
//echo $tmp;
//printf($reg["body_type"]);
}
$Result->free();
} else {
echo "no results\n";
}
//$conbd->free();
//<option value="">All</option>
}