Hello, I've been doing pretty well w/ my site so far but the powers-that-be requested a last minute addendum to the code and I'm not sure how to write it. I was hoping you folks could be of assistance to this developer-in-training.
As it stands, a certain page (random.cfm) will pull info based on the url.id for a client company (demographics mainly), then accept two numbers: the first being the number of that clients' employees they would like to drug-screen, and the second being a few 'backup' employees in case one of the primarily chosen employees is out sick or something like that. I have that portion of the page working. In fact, if the end-user is for whatever reason dissatisfied with their initial recordset, they can press the "Enter" button again and have a different random set of donors pulled. The addendum is we wish to have a button that, when pressed, takes the CURRENT randomized (by newID() ) recordset and COMMITS it (all fields from the 'rs' query with the addition of the company name and time/datestamp) to a different table, called DONOR_LOG. Here, each record from the randomized recordset will be given its own record as well, and will be able to be pulled up from a second page on the site (but I don't imagine the coding of that to be very difficult). I'm certain my problem is in the last <cfif> block, but if someone could point out those mistakes, I am still learning CF after all, and perhaps explain to me a more elegant approach to effecting this functionality, I would be very grateful. I assume it has something to do with me either reusing 'i' as an index or the block of <cfsets> nested within the last <cfif> block. Here is the code, thanks in advance, all! <cfparam name="form.company" default=""> <cfparam name="form.rows" default="0"> <cfparam name="form.alts" default="0"> <cfparam name="numberDonors" default="0"> <!--- Determines and sets the co. we are working w/ based on url.id ---> <cfquery name="rsClient" datasource="test"> SELECT clientid,clientname,derFname,derLname,derPhone,derExt,derFax FROM CLIENTS WHERE clientid='#url.id#' </cfquery> <cfset form.company = rsClient.clientname> <!--- Determines no. of possible donors from the pool of employees ---> <cfquery name="rsDonor" datasource="test"> SELECT kcid FROM donor WHERE company='#form.company#' </cfquery> <cfset numberRecords = rsDonor.recordcount> <html> <head> <title>Random Donor Selection</title> <!--- Hides buttons when printing random donor list---> <style type="text/css" media="print"> #prtBtn{display:none;} #entBtn{display:none;} #homBtn{display:none;} #comBtn{display:none;} </style> </head> <cfoutput> <body style="margin: 0px; padding: 0px; font-family: 'Trebuchet MS',verdana;" bgcolor="d2d8c7"> <table width="100%" cellpadding="0" cellspacing="0" border="0" bgcolor="777d6a"> <tr> <td colspan="2"><h4>Company:#rsClient.clientname#</h4></td> <td align="right"><h4>D.E.R. for #rsClient.clientname#:#rsClient.derFname# #rsClient.derLname#</h4></td> <tr> <td colspan="2"><h4>Total Employees:#numberRecords#</h4></td> <td align="right"><h4>D.E.R. Phone No.:#rsClient.derPhone# <cfif rsClient.derExt GT 0> Ext. #rsClient.derExt# </cfif></h4></td> </tr> <tr> <td colspan="2"><h4>Date:#DateFormat(now(), 'mmmm d, yyyy')#</h4></td> <td align="right"><h4>D.E.R. Fax No.:#rsClient.derFax#</h4></td> </td></table> <table width="100%" cellpadding="0" cellspacing="0" border="0" bgcolor="b8860b"> <tr> <!--- Select no. of random donors desired... ---> <td bgcolor="b8860b">Random Donors:</td> <form id="form" method="post"> <td bgcolor="b8860b"><input id="rows" name="rows" type="text" maxlength="2" size="3" value="#form.rows#" /></td> <!--- ...and alternates ---> <td>Alternates:</td> <td bgcolor="b8860b"><input id="alts" name="alts" type="text" maxlength="2" size="3" value="#form.alts#" /></td> <td bgcolor="b8860b"><input id="entBtn" type="submit" value="Enter"></td> <td bgcolor="b8860b"><input type="button" id="prtBtn" onClick="window.print()" value="Print Page" /></td> </form> </tr> </table> <cfset rows="#val(form.rows)#"+"#val(form.alts)#"> <!--- Pull the randoms from the DB ---> <cfif form.rows GT 0> <cfquery name="rs" datasource="test"> SELECT TOP #rows# * FROM DONOR WHERE company='#form.company#' ORDER BY newid() </cfquery> </cfif> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr><td colspan="9"><center><input type="button" id="homBtn" onClick="parent.location='index.cfm'" value="Homepage"></center></td></tr> <cfif form.rows GT 0> <tr> <td colspan="1"><strong>EID</strong></td> <td colspan="2"><strong>FIRST NAME</strong></td> <td colspan="2"><strong>LAST NAME</strong></td> <td colspan="2"><strong>SUPERVISOR</strong></td> <td colspan="1"><strong>PHONE NO.</strong></td> <td colspan="1"><strong>SSN</strong></td> </tr><br> <tr><td colspan="9"><center><em><strong>---PRIMARIES---</strong></em></center></td></tr> </cfif> <!--- Display the records ---> <cfloop index="i" from="1" to="#val(form.rows)+val(form.alts)#"> <tr> <td colspan="1">#rs.eid[i]#</td> <td colspan="2">#rs.first[i]#</td> <td colspan="2">#rs.last[i]#</td> <td colspan="2">#rs.supe[i]#</td> <td colspan="1">#rs.phone[i]#</td> <td colspan="1">#rs.ssn[i]#</td> </tr> <!--- Visually separate alts from the primaries ---> <cfif i EQ form.rows AND form.alts GT 0> <tr><td colspan="9"><center><em><strong>---ALTERNATES---</strong></em></center></td></tr> </cfif> </cfloop> <!--- If satisfied with results, commit the log of randomly-chosen donors to DB ---> <cfif form.rows GT 0> <tr> <td colspan="9"> <form name="commit" method="post"> <center> <input type="submit" id="comBtn" value="Commit to Donor Log" /> <cfloop index="i" from="1" to="#val(form.rows)+val(form.alts)#"> <cfset commit.eid[i] = rs.eid[i]> <cfset commit.first[i] = rs.first[i]> <cfset commit.last[i] = rs.last[i]> <cfset commit.supe[i] = rs.supe[i]> <cfset commit.phone[i] = rs.phone[i]> <cfset commit.ssn[i] = rs.ssn[i]> <cfset commit.company[i] = rs.company[i]> <cfquery name="rsCommit" datasource="test"> INSERT INTO DONOR_LOG( eid, first, last, supe, phone, ssn, company, dos) VALUES( '#commit.eid[i]#', '#commit.first[i]#', '#commit.last[i]#', '#commit.supe[i]#', '#commit.phone[i]#', '#commit.ssn[i]#', '#commit.company[i]#', '#dateFormat(now())#') </cfquery> </cfloop> </center> </form> </td> </tr> </cfif> </table> </cfoutput> </body></html> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:354040 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm