OK first, this is just a perfect example of why mixing presentation code and
processing logic together in one file is a horrible idea. Again, just to
keep driving this point, any basic CF book will explain to you why this is
terrible and how to separate things.

So let's break this down in terms of what the code you're showing actually
does:

If a form button is present...
Loop over the options query and for each row...
Get the id for that option...
Then loop over the list of options passed in the form and for each list
item...
Query the database looking for an option that is already there...
If there are no options already there with the matching option value...
Update the option.

I would start by dumping the query results and looking at the debug data to
confirm that the SQL that is running is actually the SQL you think is
running. I suspect that the problem is here:

<cfquery name="getOptions2" datasource="cfelsunrise" dbtype="odbc" >
       select * from questionOptions where id in (#option2#) and options
='#variables.this#'
</cfquery>

What is the query even for? If this returns no records then the update will
always happen. So the problem is probably here.

It's quite disturbing that after looking at this for 15 minutes and having
you try to explain it twice I still have almost no idea of what this code is
supposed to be doing.





On Fri, Apr 25, 2008 at 2:25 PM, erik tom <[EMAIL PROTECTED]> wrote:

> Well I started by creating a survey. Once the servey header is created I am
> creting a question. the question is created well. So mu next step is create
> a option(label that will assosiated with the choice).
>
> Here is the code
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
> http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> <html xmlns="http://www.w3.org/1999/xhtml";>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
> <title>Add/Remove Options</title>
>
> <cfquery name="getOptions" datasource="cfelsunrise" dbtype="odbc" >
>        select * from questionOptions where questionid=#questionID# and
> surveyID=#surveyID#
> </cfquery>
>
> </head>
> <cfoutput>
> <!---<cfif getOptions.recordcount gt 0>
>        <cfset optionID=#ValueList(getOptions.id)#>
> </cfif>--->
>
>
>
> <body>
> <cfoutput><form action="##" method="post" id="menu" name="menu" >
> <input type="hidden" name="questionID" id="questionID" value="#questionID#"
> />
> <input type="hidden" name="surveyID" id="surveyID" value="#surveyID#" />
> <input type="hidden" name="optionID" id="optionID" value="#getOptions.id#"
> />
> </cfoutput>
>
>
> <h1 align="center">Add/Remove Options</h1>
>
>
>
> <cfloop query="getOptions">
>        Option &nbsp;#getOptions.currentrow#:&nbsp;<input type="text"
> name="opt" id="opt" size="40"
> value="#getOptions.options#"/>#getOptions.id#<br>
>   <cfoutput> <input type="hidden" name="optionID" id="optionID"
> value="#getOptions.id#" /></cfoutput>
> </cfloop>
>
>
>
> <br />
> <br />
>
>
> <input type="submit" name="btnOption" id="btnOption" value="Save Options" >
>
> <!---<input type="submit" name="btnAdd" id="btnAdd" value="Add Option"
>  />--->
> </form>
> <cfdump var="#form#">
> <cfif isDefined("btnOption")>
> <cfloop query="getOptions">
>                <cfset option2=#getOptions.id#>
>        <cfloop index="i"  from="1" to="#ListLen(form.opt)#">
>                 <cfset variables.this=ListGetAt(form.opt,i)>
>
>
>                         <cfquery name="getOptions2"
> datasource="cfelsunrise" dbtype="odbc" >
>        select * from questionOptions where id in (#option2#) and options
> ='#variables.this#'
> </cfquery>
>
>                <cfif getOptions2.recordcount eq 0>
>
>                        <cfquery name="qryOptionSave2"
> datasource="cfelsunrise" dbtype="odbc">
>                                update questionOptions set
> options='#variables.this#' where id='#option2#' and surveyID=#surveyID# and
> questionID=#questionID#
>                        </cfquery>
>                </cfif>
>
>        </cfloop>
>       </cfloop>
>     <cflocation url="addRemoveQuestion.cfm?surveyID=#surveyID#"
> addtoken="no">
> </cfif>
>
> </cfoutput>
> </body>
> </html>
>
>
>
> >Since I have no idea what form.opt contains, or what is in the getOptions
> >query, or what is in getOptions2, it's impossible to help you. Honestly
> this
> >is so convoluted and has such confusing naming conventions I can't even
> >GUESS at what this is supposed to do. I mean, what kind of names are
> "opt",
> >"i", "this", and "getOptions2"? Code is supposed to be self-documenting,
> and
> >one of the ways it does that is by using meaningful variable names.
> >
> >I really am trying to help you here Erik. You're a very interesting case.
> I
> >mean, do you have a specific reason for refusing to actually read through
> a
> >CF book or a SQL book? You do realize that a huge number of the problems
> you
> >post about would be solved if you would just do that, right?
> >
> >And I guess I'm a glutton for punishment because I keep responding to you
> to
> >try and nudge you in the right direction. OK, clearly explain to me what
> you
> >want this code to do. What are you starting with, and what do you want the
> >end result to be?
> >
> >
> >
> >On Fri, Apr 25, 2008 at 1:36 PM, erik tom <[EMAIL PROTECTED]> wrote:
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;192386516;25150098;k

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:304257
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to