Much better... though still a whole bunch of stuff I want to change there.
:$
But anyway, yeah, if you make it to "
ORDER BY WoodCount DESC" in your count query, then all you need is
<cfset WoodType = Count.WoodType[1] /> instead of that cfoutput loop.
(Or, you can skip that entirely, and later on just use
#Count.WoodType[1]# directly.)
You can probably save a small bit of memory by putting a "TOP 1" after the SELECT too, since by then you'll only care about the first row, but it'll still work without that, just not as efficiently.
All this is just an internal tool, yes - not something that will be publicly available?
In general, you should never directly do #form.whatever# or #url.whatever# or #cookie.whatever# inside a cfquery, because it potentially allows people to inject SQL, which is bad.
Solution is to use query parameters, like this:
code:
AND rudID = <cfqueryparam value="#form.batch#" />
Which prevents SQL injection (and sometimes makes it easier for a database to optimise queries, so can make it faster too).
Same thing applies on the HTML side - to prevent people injecting HTML/JavaScript you need to use HtmlEditFormat for any unsanitized user input:
code:
Run ID = <cfoutput>#HtmlEditFormat(form.batch)#</cfoutput>
Of course, that matters more for stuff on the actual internet - if this is a local tool then it's a question of if you can trust your work colleagues, but both of them are good habits to get into.
:)EDITED: 21 Apr 2011 00:24 by BOUGHTONP