Skip navigation
Currently Being Moderated

Questions - Multiple Inserts

Oct 15, 2010 7:34 AM

I am making a question form - which has multiple questions - which would then

insert multiple answers (yes/no/na) and notes into a table.


I'm at a loss on how to do it - and having a brain fart...


Here is the loop to create the questions... Radio button for answer...


<cfloop query=Q StartRow=1 EndROW="#Column1NumRows#">
<td valign=top>
<td width=300 valign=top>
<cfif len(notes1)><br>#notes1#: <cfinput type="text" name="notes1" value="" size=10></cfif>   
<cfif len(notes2)><br>#notes2#: <cfinput type="text" name="notes2" value="" size=10></cfif>
<td align=center> Yes<br><cfinput type="Radio" name="answer#qid#" value="Yes"> </td>
<td align=center> No<br><cfinput type="Radio" name="answer#qid#" value="No"> </td>
<td align=center> N/A<br><cfinput type="Radio" name="answer#qid#" value="N/A"> </td>
<tr height=2 bgcolor=grey><td colspan=5></td></tr>

But I am having trouble inserting into the answer table..


I'm assuming I need to loop thru things...

I also need to attribute this to a single user...


Any help is appreciated...

  • Currently Being Moderated
    Oct 15, 2010 7:43 AM   in reply to Merle_Hanson

    Put underscores into your form field names on the radio buttons. Once you've submitted your form, you'll have a whole load of form fields named something like this:


    answer_1 = Y

    answer_2 = N

    answer_3 = Y

    answer_4 = N/A



    So, you need to loop through all your form fields and do an insert.


    <cfloop collection="#form#" item="key">

      <cfif find("answer_", key)>

        <cfset ThisQuestion = listLast(key, '_')  />

        <cfset ThisAnswer = form[key] />


          INSERT INTO answers (....)

          VALUES ( <cfqueryparam ThisQuestion />, <cfqueryparam ThisAnswer />) etc





    Not the most efficient, but that's probably not the major concern here

    Mark as:
  • Currently Being Moderated
    Oct 15, 2010 11:58 AM   in reply to Merle_Hanson

    The general idea will work.  However, the most important part, as usual, is making sure that your database schema is optimal for what you are trying to accomplish. 

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points