RE: looping query
Adam, I think that it is just bad coding.I have seen a fair amount of confusion on the point of getting values out of a query (e.g., people often seem refer to MyQuery.ColName without looping, unintentionally getting nothing but the first value).Also, I think people often don't know array notation for queries.I myself coded for some time before finding out about it.If someone were faced with the task of getting the last value from a query, I can imagine this is how they would do it. I'm sure you know all this, but I thought I'd add another voice saying, I think it's poor coding. HTH, Matthieu -Original Message- From: Adam Haskell [mailto:[EMAIL PROTECTED] Sent: Tuesday, October 05, 2004 8:42 AM To: CF-Talk Subject: looping query Ok so I inherited an application to update and I am trying to clean it up a little bit,or maybe a lot, but I keep running into this: cfloop query=MyQuery cfset revBy=MyQuery.rev_by cfset revDt=MyQuery.rev_dt /cfloop why oh why would some one do this? Is there a good explanation? Since the code is not commented I have no idea who the original author is so I can't ask him/her. At the very least wouldn't cfset revBy = MyQuery.rev_by[myquery.recordcount] cfset rev_dt = MyQuery.rev_dt[myquery.recordcount] Get you to the sane place faster? Most of these queries I think are only supposed to return one row but still I would think, especially on CF 5 which is what this app is running on, the looping would be a waste of time. Anyone's thoughts? _ [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
RE: looping query
To dereference the query variables in a nested query loop? :-) Micha Schopman Software Engineer Modern Media, Databankweg 12 M, 3821 ALAmersfoort Tel 033-4535377, Fax 033-4535388 KvK Amersfoort 39081679, Rabo 39.48.05.380 [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: looping query
If that's all that's in that loop it doesn't make much sense. There could be reasons if there's more code in the loop following that assignment. If it's a query that returns only one row then all you need is: cfset revBy=MyQuery.rev_by cfset revDt=MyQuery.rev_dt Ok so I inherited an application to update and I am trying to clean it up a little bit,or maybe a lot, but I keep running into this: cfloop query=MyQuery cfset revBy=MyQuery.rev_by cfset revDt=MyQuery.rev_dt /cfloop why oh why would some one do this? Is there a good explanation? Since the code is not commented I have no idea who the original author is so I can't ask him/her. At the very least wouldn't cfset revBy = MyQuery.rev_by[myquery.recordcount] cfset rev_dt = MyQuery.rev_dt[myquery.recordcount] Get you to the sane place faster? Most of these queries I think are only supposed to return one row but still I would think, especially on CF 5 which is what this app is running on, the looping would be a waste of time. Anyone's thoughts? [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: Looping query help
If class_enrollment is an int (or similar), you could be getting an error because of the wrapping single quotes. And before someone else says it, cfsqlparam is a good thing. --Ben Doom Austin Govella wrote: I have a listing of classes, each with a text box next to them. Users will fill in a number in the text box next to each class and then hit submit. I'm trying to loop through the results and INSERT a class_id, section number, enrollment number, and date for each class. I use the following code to loop through checkboxes on another page, so I'm not sure why this gives me an error. (Syntax error in INSERT INTO statement.) !-- create lists for values --- cfset class_id_list=#form.class_id# cfset section_no_list=#form.section_no# cfset class_enrollment_list=#form.class_enrollment# !--- loop through and set enrollment for each class --- cfloop index=i from=1 to=#ListLen(class_id_list)# cfquery name=q_approve_class datasource=#application.db# INSERT INTO tbl_class_enrollment (class_id, class_enrollment, section_no, date) VALUES (#ListGetAt(class_id_list, i)#, '#ListGetAt(class_enrollment_list, i)#', '#ListGetAt(section_no_list, i)#', '#enrollment_date#'); /cfquery /cfloop This is the outputted SQL: INSERT INTO tbl_class_enrollment (class_id, class_enrollment, section_no, date) VALUES (841, '2', '03280', '4/20/2004'); Any ideas? -- Austin [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
Re: Looping query help
Off the top of my head, I would suggest using cfqueryparam. Doug Austin Govella wrote: I have a listing of classes, each with a text box next to them. Users will fill in a number in the text box next to each class and then hit submit. I'm trying to loop through the results and INSERT a class_id, section number, enrollment number, and date for each class. I use the following code to loop through checkboxes on another page, so I'm not sure why this gives me an error. (Syntax error in INSERT INTO statement.) !-- create lists for values --- cfset class_id_list=#form.class_id# cfset section_no_list=#form.section_no# cfset class_enrollment_list=#form.class_enrollment# !--- loop through and set enrollment for each class --- cfloop index=i from=1 to=#ListLen(class_id_list)# cfquery name=q_approve_class datasource=#application.db# INSERT INTO tbl_class_enrollment (class_id, class_enrollment, section_no, date) VALUES (#ListGetAt(class_id_list, i)#, '#ListGetAt(class_enrollment_list, i)#', '#ListGetAt(section_no_list, i)#', '#enrollment_date#'); /cfquery /cfloop This is the outputted SQL: INSERT INTO tbl_class_enrollment (class_id, class_enrollment, section_no, date) VALUES (841, '2', '03280', '4/20/2004'); Any ideas? -- Austin [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]