Use cfloop in a query that INSERTS data into one row?

Hi,

First a  quick thanks to everyone on EE for all their help

I need some help, this is a registration page for a bball league, the INSERT statement I'm using does it's job but inserts data into different rows, I need it all to go to the same row.

User chooses which division(s) they want to register for here

<cfquery name="getTourneys" datasource="hoops">
SELECT   *
FROM   tourneyInfo
WHERE num = #URL.num#
</cfquery>

THE FORM

<cfform action="register2.cfm" name="myForm">
  <cfoutput>      
    <cfloop index="i" from="1" to="9">
      <cfif Evaluate("getTourneys.div" & i) NEQ "">
        <cfinput name="chkdiv" type="checkbox" value="#Evaluate("getTourneys.div" & i)#">
        <font size="4">#Evaluate("getTourneys.div" & i)#</font><br><br>
            <input name="#num#" type="hidden" value="#num#">
      </cfif>
    </cfloop>  
  </cfoutput>

  <input type="submit" name="Submit" value="Submit">
</cfform>

ACTION PAGE-----------------------------------------------------------------------------------------

DATA FROM FORM INSERTED INTO ACCESS, IT INSERTS FINE BUT INTO DIFFERENT ROWS, I NEED IT TO GO TO THE SAME ROW.

<cfif IsDefined('form.chkdiv')>
  <cfloop index="i" from="1" to="#ListLen(form.chkdiv)#">
    <cfquery datasource="xxx">
    INSERT INTO infoTourneyTeams(div#i#)
    VALUES(<cfqueryparam cfsqltype="cf_sql_varchar" value="#ListGetAt(form.chkdiv,i)#">)
    </cfquery>
  </cfloop>
</cfif>

Any help appreciated.
Thanks,
Greg Smith

gregoryrsmithAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mmc98dl1Commented:
First, I think your database structure needs some work - heres the reason.

If you had 50 divisions, then in your infoTourneyTeams table you would need 50 rows, and every time a division is created you would need to create another row to cater for it.

Realistically you should have your division table, a joining table with the divisionid and teamid in, then your infotourneyteam table, this would then mean your database can scale very nicely.

Second - to make it work the way you have, the most effective way i think, you need to put in comma delimited list in one cell, so use

<cfquery datasource="xxx">
    INSERT INTO infoTourneyTeams (div)
    VALUES(<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.chkdiv#">)
    </cfquery>
0
Renante EnteraSenior PHP DeveloperCommented:
Hi gregoryrsmith!

I just need some clarification about the flow.

:: FORM PAGE ::
checkbox 1 - div1 - value1
checkbox 2 - div2 - value2
checkbox 3 - div3 - value3
... until checkbox 9 ...

If checkbox 3 is chosen, it should be save into "div3" of table "infoTourneyTeams" considering that checkboxes 1 and 2 are not chosen.  I suspect this is what you want to overcome but the action page doesn't do the requirements.  Am i right ???

So, your code needs to be revised again.  #-o

:: REVISED FORM PAGE ::
<cfform action="register2.cfm" name="myForm">
  <cfoutput>      
    <cfloop index="i" from="1" to="9">
      <cfif Evaluate("getTourneys.div" & i) NEQ "">
        <cfinput name="chkdiv#i#" type="checkbox" value="#Evaluate("getTourneys.div" & i)#">
        <font size="4">#Evaluate("getTourneys.div" & i)#</font><br><br>
          <input name="#num#" type="hidden" value="#num#">
      </cfif>
    </cfloop>  
  </cfoutput>

  <input type="submit" name="Submit" value="Submit">
</cfform>

* Note : In this case, you don't need to have the same name for your checkboxes.

:: REVISED ACTION PAGE ::
<cfloop index="i" from="1" to="9">
  <cfif IsDefined('form.chkdiv#i#')>
    <cfquery datasource="xxx">
    INSERT INTO infoTourneyTeams(div#i#)
    VALUES(<cfqueryparam cfsqltype="cf_sql_varchar" value="#form['chkdiv#i#']#">)
    </cfquery>
  </cfif>
</cfloop>

Hope this helps you.  Just try it.


Goodluck!
eNTRANCE2002 :-)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gregoryrsmithAuthor Commented:
That's it exactly. You are a lifesaver!! Add that to your already extensive resume.

Thanks again,
G
0
Renante EnteraSenior PHP DeveloperCommented:
Oh!  That's great.

I'm glad that I have helped you.  Hope to help you again.


Regards!
eNTRANCE2002 :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.