take your point, I get it now :)

----- Original Message ----- 
From: "Rich Wild" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, June 06, 2003 5:11 PM
Subject: RE: [ cf-dev ] form.fieldnames


> > It does seem a little overcomplicated doing it this way
> > though. Surely it
> > would be easier to loop the names of the fields to set up form params
> > defaulted to 0 and then if a value of 1 is passed, insert
> > into the join
> > table?
>
> not really, as that way you need to find all your ids again (prob by a
> database query), then loop over these using <cfparam> to default them all,
> and then check whether each one is zero or not before inserting.
>
> If you do it the way Ian was doing it, then you only need one <cfparam> to
> ensure that there the form variable exists, even if its empty, and then
you
> just need to loop over the that list.
>
> If its empty, no inserts happen, if its not, then those ids get entered
into
> the database. You don't need to check if they're zero or something else.
>
> so compare this:
>
> form.cfm ===========
> <cfoutput query="myIds">
> <input type="checkbox" name="myBox" value="#id#"><br>
> </cfoutput>
> ====================
>
> action.cfm ==========
> <cfparam name="form.myBox" default="">
>
> <cfif listlen(form.myBox)>
> <cfquery.....
> Do insert.....
> </cfif>
> =====================
>
> to this:
>
> form.cfm ===========
> <cfoutput query="myIds">
> <input type="checkbox" name="myBox_#id#" value="1"><br>
> </cfoutput>
> =====================
>
> action.cfm ==========
> <cfquery name="myBoxes" datasource="#dsn#">
> SELECT id FROM myBoxes
> </cfquery>
>
> <cfloop query="myBoxes">
> <cfparam name="form.myBox_#id#" default="0">
> </cfloop>
>
> <cfloop query="myBoxes">
> <cfif form["myBox_" & id]>
> <cfquery...
> Do Insert.....
> </cfif>
> </cfloop>
> =====================
>
>
> Method 1 is faster <cf_emphasis>in this instance</cf_emphasis>.
>
> There are of course, other times when you method would be more correct,
> which I can't even begin to think of this close to the booze hour.
>
> Rich
>
>
> -- 
> ** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/
>
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> For human help, e-mail: [EMAIL PROTECTED]
>
>



-- 
** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
For human help, e-mail: [EMAIL PROTECTED]

Reply via email to