Hi all!
Problem: A user selects from a group of check boxes and
submits. When going to edit the info, can't figure out the
best way to pull the info back out of the database into the
checkboxes (so users can see and edit which boxes they have
checked).
Background:
I am creating a contact management application. In the
create a new contact area, the user has a has a list of
check boxes (they wanted check boxes for some reason) for
adding the new contact to one or several groups. Ex: the
new contact can be in the sales and admin groups or whatever
(like 20 groups to choose from). Anyway, there are two
basic tables in my database, 1 for contact information and 1
with group names and descriptions. On the enter a new
contact form, the group names and descriptions are being
pulled out of the group table for the checkboxes:
<cfoutput query="Groups">
<tr>
<th align="right"></th>
<td>
<b>#GroupName#</b><input type="checkbox" name="Groups"
value="#GroupName#">
#Description#
</td>
</tr>
</cfoutput>
This works ok. It enters the names of any groups checked
into the contacts table in one field called "Groups" with
comma separators . I'm using this code to pull the info
back out for the editing contact form:
<cfquery datasource="datasource" name="Contact">
SELECT g.GroupID, g.GroupName, g.Description, c.ContactID,
c.FirstName, c.LastName, c.MiddleInit, c.Address, c.City,
c.StateOrProvince, c.ZipCode, c.Country, c.CompanyName,
c.Title,
c.WorkPhone, c.WorkExtension, c.HomePhone, c.CellPhone,
c.Fax,
c.Email, c.ReferredBy, c.Notes, c.Groups
FROM Groups g, Contacts c
WHERE c.ContactID=#ContactID#
</cfquery>
...
<CFIF #Groups# CONTAINS #GroupName#>
<tr>
<th align="right"></th>
<td>
<b>#GroupName#</b><input type="checkbox" name="Groups"
value="#GroupName#" CHECKED> #Description#
</td>
</tr>
</CFIF>
<CFIF #Groups# DOES NOT CONTAIN #GroupName#>
<tr>
<th align="right"></th>
<td>
<b>#GroupName#</b><input type="checkbox" name="Groups"
value="#GroupName#"> #Description#
</td>
</tr>
</CFIF>
This actually works ok too except for the fact that a table
full of all the same info, except for the group checkbox,
appears for every group. Ex: 3 groups - 1st table has all
info and then Group1 checkbox (either checked or not), 2nd
table...Group2 checkbox, third table...Group3 checkbox.
I'm thinking that it has to do with how the groups are being
stored in the database? Is there a better way?
Thanks for any help!
Christin
------------------------------------------------------------------------------
Archives: http://www.eGroups.com/list/cf-talk
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.