![]() |
![]() |
||||||
|
|||||||
| Tags: |
![]() |
|
|||
|
Sorry for this newbie questions.
I have a simple quetions where people can answer What flavor ice cream you want? and they can select mutiple ones <select multiple size="12" name="icecream"> <option value="vanilla" selected>Vanilla <option value="choco" selected>Choco <option value="mango" selected>mango <option value="coffe" selected>coffe <option value="fudge" selected>fudge </select> Now the data get stored as a comma delemeted for example, vanilla,choco,fudge I need to allow the users to edit their selection if they want to. So when I query the field from the DB the value comes back as above (comma delemeted). I can add a CFloop to return each on one line. Now my question is how can I make let people see what they have selected before and in the form where they can modify their selection. When I add the loop and cfif statment, I get the selections repeated few time. So I want to have the select stament above with the option SELECTED if the user have chosen that flavor before. Again I have not programmed in years and very rusty with this. Any help is appreciated. |
| Sponsored Links |
|
|||
|
The listFind() and listContains() functions.
andy99 wrote: > > Now the data get stored as a comma delemeted for example, vanilla,choco,fudge > That is a really bad database design choice. It will not scale and there are a lot of normal database functionality one will find very difficult, if not down right impossible with this. One should not store a list of values in a field in a database. This just screams for normalization where you create a related table of User_Flavors that contains the ids of the user and their chosen flavors, one record per flavor per user. This would then join the users table to the flavors table. Just warning you, you are heading down a road that quickly leads to difficulty. Just search these list for databases and list values to see some of the trouble this causes. |
|
|||
|
Thanks Ian. Yeah, I was trying to avoid checkboxes and thought this will be an
easy way out. Since this is a very small application (user id and flavor) I thought it will be simpler. So I tried the 2 functions but they both return 0. <cfquery datasource="shop" name="mydb"> select * from icecream where id like 'form.id' </cfquery> <cfoutput query="mydb"> #ListFind(ice, ",")# </cfoutput> Again, I would like to output them in the option fields and if they selected originall then I will add CHECKED to the option. |
|
|||
|
andy99 wrote:
> Thanks Ian. Yeah, I was trying to avoid checkboxes and thought this will be an > easy way out. > Since this is a very small application (user id and flavor) I thought it will > be simpler. > > So I tried the 2 functions but they both return 0. > <cfquery datasource="shop" name="mydb"> > select * from icecream > where id like 'form.id' > </cfquery> > > <cfoutput query="mydb"> > #ListFind(ice, ",")# > </cfoutput> > > Again, I would like to output them in the option fields and if they selected > originall then I will add CHECKED to the option. > |
|
|||
|
andy99 wrote:
> <cfoutput query="mydb"> > #ListFind(ice, ",")# > </cfoutput> That is not a complete list find function. At least not complete enough to do what you want. I suspect that it is trying to find a value of a comma. I would expect something that looked like this. #listFind(mydb.ice,"chocolate")# OR if you like to be complete. #listFind(mydb.ice,"chocolate",",")# And then your select code would look something like this. <select ...> <option #iif(listFind(mydb.ice,"chocolate"), DE('selected="selected"'), DE(''))# value="chocolate">Chocolate</option> <option #iif(listFind(mydb.ice,"vanilla"), DE('selected="selected"'), DE(''))# value="vanilla">vanilla</option> .... </select> |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
- Contact Us
-|-
Adobe Dreamweaver Forums -|-
Archive -|-
Top -|-Rules/Disclaimer-|-Help/Support-|-Advertise