Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8959881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:32:46+00:00 2026-06-15T15:32:46+00:00

Got stuck with an issue and thought I might see if anyone had any

  • 0

Got stuck with an issue and thought I might see if anyone had any ideas on how to fix it.

Basically, I pass in multiple values under a singular variable, and I want to use a loop to extract each individual value and insert it at the same time.

For example, ischecked is the variable I use to pass in device values. If I were to select two devices, press submit and dump the variable #form.ischecked# in my processing page, I would get a value that says 41,42 for example. I need a way to split these values up, and figured a cfloop and insert would be perfect for that.

This is all done in a cfc, if that matters.

        <cfset devicearray = ArrayNew(1)>
        <cfset temp = ArrayAppend(devicearray, #ischecked#)>
        <cfset test = ArrayToList(devicearray, ",")>
        <cfset length= ListLen(test)>\
        \\this loop takes the amount of devices selected, and outputs the length of the list. 

I use this to find out how long the insert loop should go for.
I could have also just checked the length of the array originally, but I was going to use the list for another purpose as well.

    <cfset devicetest = #form.ischecked#>

        <cfset usertest = #form.userid#>

        \\form.ischecked is the variable that contains the device IDs

        \\form.userid is the variable that contains the User IDs

        <cfquery name="loopquery" datasource="Test">
        <cfloop from="1" to="#length#" index="i">

        \\loop from 1 to "length", the number of Devices selected as specified earlier

        INSERT INTO Loan (DeviceID, UserID)
        VALUES ("#Evaluate("devicetest#i#")#","#Evaluate("userID#i#")#" )
        </cfloop>
        </cfquery>

So basically that’s where I’m stuck at, the loop goes over the values but it looks for devicetest1 instead of device test (because of the index), but I can’t for the life of me figure out how to pass in the values so that it picks out each one individually.

I’ve seen some examples where people have appended the index (i) with the value, then used it to insert, but didn’t really understand how it would have worked.

Thanks,
Jordan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:32:48+00:00Added an answer on June 15, 2026 at 3:32 pm

    I’m not understanding what the point of deviceArray is. You say form.isChecked is already a list containing a list of device id’s. If it’s coming in from a form submission, it is already comma delimited.

    As such, there is no real need to do anything but a listlen to get the length of it.

    Your code may be taken out of context, but to be complete, make sure you param form.isChecked and form.userID

    <cfparam name="form.isChecked" default="">
    <cfparam name="form.userID" default="">
    

    At this point, I would also personally do some error checking to make sure that the lengths of the two variables match.

    <cfif listLen(form.isChecked) NEQ listLen(form.userID)>
        <!--- abort or do something else --->
    </cfif>
    

    There’s no need to actually write a separate insert for each loop. Most databases will allow you to insert multiple rows with one statement. Since you’re just looping through each of the values in form.userID and form.isChecked, you can just do a listGetAt – making sure to use a cfqueryparam to sanitize your data inputs. Note that I just assumed your deviceId and userId values are integers. Change those as necessary.

    <cfquery name="insert" datasource="test">
        INSERT INTO Loan (DeviceID, UserID)
        VALUES
        <cfloop from="1" to="#listLen(form.userID)#" index="i">
           <cfif i GT 1>
               ,
           </cfif>
           (
               <cfqueryparam value="#listGetAt(form.isChecked,i)#" cfsqltype="CF_SQL_INTEGER">,
               <cfqueryparam value="#listGetAt(form.userID,i)#" cfsqltype="CF_SQL_INTEGER">
           )
        </cfloop>
    </cfquery>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to pass structs between processes using named pipes. I got stuck at
I got stuck in an odd issue with Android - I want to have
Currently I am stuck at the issue to generate a query with multiple paths.
I am new to grails and i got stuck with another issue. I have
I have got stuck in a dump issue but am not able to work
I'm making use of ZeroMQ from .NET and got stuck trying to fix a
Got a pretty strange issue here, maybe someone had similar experience. When loading http://magento.dev/index.php/cmd/sales_order_status/
I was going through this article and got stuck with one issue. Imagine I
I am desining a database and got stuck with this issue: My case is
I got stuck with solving a seemingly easy issue. http://jsfiddle.net/HAKvN/3/ By clicking the black

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.