[thelist] cfloop

Isaac Forman isaac at members.evolt.org
Wed Jul 19 09:13:06 CDT 2000


Palyne,

> I have a system where the admin gets a list of records and for each
> one should have the option to change 'status' to 'live'.  I want to
> just make a checkbox for this on each record-row-output where if it's
> NOT checked (the default), the status for a record doesn't change,
> and if it is, then status=live is updated for that record.

OK, I think I know what you're after. I've used something like this for an
auction system which allows admins to "activate" certain re-auctionable
services.

I'll start with the update code I use:

    <cfelseif url.type is "updateall">
    <cfparam name="form.auctionid" default="">
    <cfquery name="deactivateall" datasource="#db#">
    update auction set auctionactive = '0';
    </cfquery>
    <cfloop index="loopitem" list="#form.auctionid#">
        <cfquery name="activesome" datasource="#db#">
        update auction set auctionactive = '1' where auctionid = #loopitem#;
        </cfquery>
    </cfloop>
    <cfset session.pageresponse = "The auctions have all been updated.">
    <cflocation url="auctions.cfm">
    </cfif>

Now, auctionid is the comma delimited list of IDs which have a corresponding
"checked" checkbox. This is achieved by using the same name ('auctionid') for
each checkbox on the page.

My method might be a bit scrappy, but it first deactivates every auction, and
then activates those that have been checked by setting their 'auctionactive'
value to 1.

Here's the form (I've cut out all unnecessary code) with the checkboxes:

	<cfoutput>
	<tr><td>
	<input type="checkbox" name="auctionid" value="#auctionid#"
	<cfif auctionactive is 1>checked</cfif>
	> #auctiontitle#
	</td></tr>
	</cfoutput>

As I said, my method for accomplishing this could definitely be improved, but
I'll let the professionals help you with that.


isaac





More information about the thelist mailing list