Post new topic Reply to topic  [ 8 posts ] 

Board index : Music Talk : Rock/Pop

Author Message
 Post subject: nmr: Cold Fusion/Access database question
PostPosted: Tue May 09, 2006 1:04 pm 
Offline
Go Platinum
User avatar

Joined: Tue Oct 26, 2004 1:20 pm
Posts: 7730
Location: Portland, OR
Any of you out there Cold Fusion aficionados? I'm trying to do something relatively simple, and having a hell of a time figuring it out. I've got an Access database (I know, I know... spare me the lecture) with a table that has a listing of people who have signed up/taken CAD training classes. The instructors of the classes would like to be able to go in, pull up their class roster, and check a box next to the signee's name to vouch for their attendance. So I've got a query that pulls up all the attendees for the class, and then has a checkbox that you can check "yes." My problem lies in updating multiple rows in the table. (btw, each row has their own unique identifier/key, so it's not like I'm trying to update duplicate info here)

I've tried cfloops, I've tried deleting and re-inserting the data with the new info, I've tried cfupdate and cfquery with update SQL statements... no dice. Am I missing something? Can anyone shed some light?

Any advice/help is appreciated. It seems like it should be so freaking simple.


Back to top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 1:17 pm 
Offline
frostingspoon
User avatar

Joined: Sat Oct 23, 2004 1:38 pm
Posts: 10237
Location: Hill
alright, i've never used CF, but a little poking around sez this is one way:

Code:
<CFLOOP index="thisID" from="1" to="#form.num_students#">
  <CFQUERY NAME="update" datasource="whatever.data">                 
    UPDATE ROSTER               
      ATTENDED= '#evaluate("FORM.ATTENDED_#thisID#")#'             
      WHERE
        STUDENT_ID= '#evaluate("FORM.student_id_#thisID#")#'   
        CLASS_ID='#form.class_id#'
        CLASS_DATE='#form.class_date#'
   </CFQUERY>     
</CFLOOP>


if i understand correctly, that will loop over all values of #thisID# and update each student for that class. of course, i'm totally guessing at the structure of your table, but i'm sure it's something like the above. i'm not sure of the role of evaluate() though - may be unnecessary.


Back to top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 1:23 pm 
Offline
Go Platinum
User avatar

Joined: Tue Oct 26, 2004 1:20 pm
Posts: 7730
Location: Portland, OR
Thanks, Aaron... yeah, I've tried that already, and while it should work, it didn't. I don't think it's a table structure issue, but there's something going on with my update syntax. I'll keep hammering, but thanks for trying!


Back to top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 1:24 pm 
Offline
frostingspoon
User avatar

Joined: Sat Oct 23, 2004 1:38 pm
Posts: 10237
Location: Hill
dude, just post the code. i'll take it down after it's sorted out.


Back to top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 1:27 pm 
Offline
Go Platinum
User avatar

Joined: Tue Oct 26, 2004 1:20 pm
Posts: 7730
Location: Portland, OR
here are the various methods I've tried so far:

method 1:
<cfquery datasource="training">
UPDATE SIGNUPTEST
SET Attended = #Form.Attended#
WHERE Auto = #Form.Auto#
</cfquery>

method 2:
<CFQUERY NAME="Update" DATASOURCE="training">
<CFLOOP list="#Auto#" index="Auto">
UPDATE SIGNUPTEST (Auto,Attended)
VALUES (#Form.Auto#, #Form.Attended#)
</CFLOOP>
</CFQUERY>

method 3:
<cfquery name="deleteItems" datasource="training">
DELETE * FROM SIGNUPTEST WHERE Auto = '#Form.Auto#'
</cfquery>

<cfloop list="#form.Attended#" index="Auto">
<cfquery datasource="training" name="insertItems">
INSERT INTO SIGNUPTEST(Attended)
VALUES('#Attended#')
</cfquery>
</cfloop>


Back to top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 1:29 pm 
Offline
frostingspoon
User avatar

Joined: Sat Oct 23, 2004 1:38 pm
Posts: 10237
Location: Hill
What is Auto? Is that the class identifier?

Also, post the html of the form if you don't mind.


Last edited by HaqDiesel on Tue May 09, 2006 1:29 pm, edited 1 time in total.

Back to top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 1:29 pm 
Offline
Go Platinum
User avatar

Joined: Tue Oct 26, 2004 1:20 pm
Posts: 7730
Location: Portland, OR
yep


Back to top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 1:34 pm 
Offline
frostingspoon
User avatar

Joined: Sat Oct 23, 2004 1:38 pm
Posts: 10237
Location: Hill
Code:
method 1:
<cfquery datasource="training">
   UPDATE SIGNUPTEST
   SET Attended = #Form.Attended#
   WHERE Auto = #Form.Auto#
</cfquery>


If, as I think you said, there's a whole list of checkboxes on this page, this won't work. You need to give each checkbox an identifier in the form, like "Attended_student_id", and then "SET Attended=Form.Attended_student_id WHERE student_id=form.student_id and Auto=form.Auto". The way you're doing it above would set only 1 value per class, unless i'm totally misunderstanding. If you're trying to set the attended value per student, per class, you can't just have one key, unless Auto represents "student x in class y".

Code:
method 2:
<CFQUERY NAME="Update" DATASOURCE="training">
   <CFLOOP list="#Auto#" index="Auto">
   UPDATE SIGNUPTEST   (Auto,Attended)   
   VALUES   (#Form.Auto#, #Form.Attended#)
   </CFLOOP>   
</CFQUERY>


Same with the above - you're looping over the class and updating 1 "Attended" value.


Back to top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

Board index : Music Talk : Rock/Pop


Who is online

Users browsing this forum: No registered users and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Style by Midnight Phoenix & N.Design Studio
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.