I have 3 tables, respectively:
-
Vehicles
- vehicle_id, vehicle_name .
-
Accessories
- acessorio_id, acessorio_name
-
Vehicle_accessories
- vehicle_id
- acessorio_id
On the vehicle registration page the accessories fields come from the accessories table as a checkbox field. When I register the vehicle, the registration is inserted in the tables vehicles and accessory vehicles .
Until this part works normally, but on the edit page I can only pick up those that have already been marked (by checkbox) during the registration of the vehicle, and what I wanted to show all the accessories of the table, including the unmarked ones, leaving only marked those that were marked during the registration.
The SQL query code of the edit page looks like this: In this query it only returns the checkboxes that have been marked in the register!
<?php
$getVehicleID = filter_input(INPUT_GET, 'vehicleID', FILTER_VALIDATE_INT);
$ReadItens = new Read;
$ReadItens->FullRead("SELECT cars.car_id,car_vehicles_and_items.car_id,car_additional.additional_id,car_additional.additional_title
FROM car_vehicles_and_items INNER JOIN cars ON cars.car_id = car_vehicles_and_items.car_id
INNER JOIN car_additional ON car_additional.additional_id = car_vehicles_and_items.additional_id where car_vehicles_and_items.car_id = : id", " id=$getVehicleID");
foreach ($ReadItens->getResult() as $lisItens):
echo "<input ";
if ($lisItens['car_id'] == $getVehicleID):
echo "checked ";
endif;
echo "type=\"checkbox\" id=\"{$lisItens['additional_id']}\" name=\"car_additional[]\" value=\"{$lisItens['additional_id']}\">";
echo $lisItens['additional_title'];
endforeach;