As always I have problems with dynamic checkboxes on a update page. There are three tables involved (properties, amenities and property_amenities). The amenities for each property, as you can guess, are stored in the table property_amenities
CREATE TABLE IF NOT EXISTS `property_amenities` (
`property_id` smallint(4) unsigned NOT NULL default '0',
`amenity_id` smallint(4) unsigned NOT NULL default '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
I can’t get my head around it how to query and output this in the update page, since I need all amenity values from the amenities table (in order for the administrator to update) and I need the the values from property_amenities table since that are the ones that needs to be checked.
I tried it with two separate queries one for all amenities and one for a particular property
SELECT
amenity_id
, amenity_gr
FROM
amenities
ORDER
BY
amenity_gr
SELECT
A.amenity_id
, A.amenity_gr
, P.amenity_id
, P.property_id
FROM
amenities A
INNER
JOIN property_amenities P
ON
P.amenity_id = A.amenity_id
WHERE
P.property_id = Url.property
and have a within the
<cfoutput query="getAmenities">
<li><input type="checkbox" name="amenity_id" value="#amenity_id#" <cfif getPropertyAmenities.amenity_id EQ
getAmenities.amenity_id>checked</cfif>>#amenity_gr#</li>
</cfoutput>
But this returns just one checkbox checked
Any suggestions?