1
I have 3 tables, respectively:
- Vehicles
- veculo_id, veculo_name.
- Accessories
- acessorio_id, accessorio_name
- Vehicles
- veculo_id
- accessorio_id
On the vehicle registration page the fields accessories come from table database accessories as a field of the kind checkbox. When I register the vehicle, the registration is inserted in the tables vehicles and vehicles.
Even this part works normally, but on the page of edit I can only catch the ones that have already been marked (by checkbox) during the registration of the vehicle, and what I wanted was to show all the accessories of the table, including those not marked, leaving only marked those that were marked during the registration.
The SQL query code of the edit page looks like this: This query only returns the checkboxes that were 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;
What have you already done? Are you creating HTML directly from a PHP file? Because there are different ways to do it. Edit the question with the code that has already been done in that part.
– Giancarlo Abel Giulian
I don’t understand very well what Voce is trying to do, Do you want to search the database for the values and put them in a checkbox with active marking? that’s it?
– RFL
Yes that’s right I want to list all accessories and stay active only those that were marked in the register!
– Gomes
Despite the editing, it’s still hard to understand what you really want.
– Edilson
from what I understand, just rip the filter from the "checked":
" id=$getVehicleID"
of consultation.– Ivan Ferrer
Bring everything without filter, in the loop, you mark what is checked.
– Ivan Ferrer