Copy link to clipboard
Copied
Hello i'm trying to use two check boxes when selected I want it to change how it does the order by. So far I have this:
<CFIF isDefined("Form.artist") IS "YES">
ORDER BY products.artist
</CFIF>
<CFIF isDefined("Form.qoo") IS "YES">
ORDER BY products.QtyOnOrder DESC
</CFIF>
This also errors out. What am I doing wrong? Can this be done using checkboxes? Anyhelp would be great.
Thanks
Copy link to clipboard
Copied
If both checkboxes are checked, you'll end up with:
ORDER BY products.artist
ORDER BY products.QtyOnOrder DESC
Which is not syntactically valid SQL.
You should be doing an if/elseif, I think.
--
Adam
Copy link to clipboard
Copied
OK I'm now trying this:
<cfif #Form.artist# IS "YES">
order by artist
<cfelseif #Form.qoo# IS "YES">
ORDER BY QtyOnOrder
</cfif>
it will work for artist, but not not for Qty On Order (qoo). What should I add/change?
Thanks
Copy link to clipboard
Copied
I generally do all that sort of logic before the query tag. Something like this:
OrderByClause = '';
Logic to change that clause.
<cfquery>
blah blah blah
#OrderByClause#
</cfquery>
With this approach, you can see what the clause is going to be before you attempt to run the query. It also allows you to output text during your conditional logic processing. Something like this
if (variable is expected value) {
writeoutput ("yes");
other code
}
else {
writeoutput("no, variable had value of " & actualvalue);
other code
}
}