First post here, found this site through this thread but the answers didn't quite cover what I'd like to ask, but looked extremely helpful, so here goes.
I have a "Settings" section of my site whereby users can save preferences for their favorite genres, There are 7 options with 3 radio boxes for each (Never Send, Like, Love). My problem from what I understand is when I loop the results in the form action page I'm not matching the results to the correct row in the DB (MySQL). So let me paste some code to explain better...
The join is just a seperate table to store the genre names, so this brings back the current users prefs.
<cfquery name="rsGetGenres" datasource="#Request.dsn#" username="#Request.dsnUsername#" password="#Request.dsnPassword#"> SELECT * FROM tbl_custpref LEFT OUTER JOIN tbl_genre ON tbl_custpref.genre_ID = tbl_genre.genre_ID WHERE cst_ID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#Client.CustomerID#" /> </cfquery>
Form: So this is the front end which loads with their saved settings, I've added the #listOfIds# through reading the thread mentioned above in an attempt to give me something to loop through on the action page.
<cfset variables.listOfIds = ValueList(rsGetGenres.genre_ID)>
<cfform action="/account/Settings-Process.cfm" id="Settings"> <cfloop query="rsGetGenres"> <cfoutput> <input type="radio" id="never_#genre_ID#" name="option_#genre_ID#" value="0" <cfif #custLike# eq 0>checked</cfif> /><label for="never_#genre_ID#">Never Send</label> <input type="radio" id="like_#genre_ID#" name="option_#genre_ID#" value="1" <cfif #custLike# eq 1>checked</cfif> /><label for="like_#genre_ID#">Like</label> <input type="radio" id="love_#genre_ID#" name="option_#genre_ID#" value="2" <cfif #custLike# eq 2>checked</cfif> /><label for="love_#genre_ID#">Love</label> </cfoutput> </cfloop> <cfoutput><input type="hidden" name="IDs" value="#listOfIds#"></cfoutput> <input type="submit" name="save" value="Save" /> </cfform>
This is what I'm trying to achieve for an update to the db, enter a new status - Never(0) Like(1) Love(2) for each row based on the form data. custLike being the option they selected (0,1 or 2) and the unique genre_ID to make sure the correct row is updated.
UPDATE tbl_custpref SET custLike = 0 WHERE genre_ID = 1 AND cst_ID = 'D6F76525-07-25-11'
Action Page. I'm still pretty new to Coldfusion so I'm sure this is a simple one! I've dumped out the form structure to make sure everythings coming through (
). It looks like its passing the newly select options through fine from the radio buttons, but I can't figure out how to loop and match the to the correct row in the DB.
<cfdump var="#form#">
<cfif structKeyExists(form, "save")>
<cfloop item="field" collection="#form#" >
<cfquery datasource="#Request.dsn#" username="#Request.dsnUsername#" password="#Request.dsnPassword#">
UPDATE tbl_custpref
SET custLike = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form[field]#">
WHERE cst_ID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#Client.CustomerID#" />
AND genre_ID = [i]????????? Not sure what to do here to update the correct row in the loop ???????????[/i]
</cfquery>
</cfloop>
</cfif>
The type of errors I've had so far are
'Incorrect integer value: 'OPTION_1,OPTION_2,OPTION_3,OPTION_4,OPTION_5,OPTION_6,OPTION_7,IDS,SAVE' for column 'custLike' at row 1 ' where I assume its trying to cram all the data into 1 field and silly things like that. I'm really just not sure how to write this.
Any help would be greatly appreciated. If I've missed explaining anything please let me know, its usually the syntax that causes me the most problems even if I know what I want todo.
Ben

New Topic/Question
Reply



MultiQuote




|