macromedia.coldfusion.database_access
[Top] [All Lists]

Re: sos (pleas how cam i insert multiple values into mysql with one in

Subject: Re: sos (pleas how cam i insert multiple values into mysql with one insert statement)
From: Azadi <azadi@xxxxxxxxxxxxx>
Date: Sun, 20 Jul 2008 10:34:18 -0400
Newsgroups: macromedia.coldfusion.database_access

in mysql the multi-row insert syntax is:

INSERT INTO tablename
(column1, column2,...)
VALUES
(row1value1, row1value2, ...),
(row2value1, row2value2,...),
...

since you mention checkboxes, i assume the values you want to insert are
not really from a db, but from a web form

make sure all your checkboxes have SAME NAME (but different VALUE) -
this when the form is submitted all selected checkboxes values will be
submitted as a comma-delimited list - you can easily loop over it to
insert the values:

<cfif structkeyexists(form, 'checkboxesname')>
<cfset loopcounter = 0>
<cfquery ...>
INSERT INTO yourtablename
(yourcolumnname)
VALUES
<cfloop list="#form.checkboxesname#" index="cbx_value">
<cfset loopcounter = loopcounter+1>
(<cfqueryparam cfsqltype="PUT_APPROPRIATE_TYPE_HERE" value="#cbx_value#">)
<cfif loopcounter lt listlen(form.checkboxesname)>,</cfif>
</cfloop>

hth


Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/

<Prev in Thread] Current Thread [Next in Thread>