Skip to main content
Inspiring
May 17, 2012
Question

check box Coldfusion 9 question

  • May 17, 2012
  • 1 reply
  • 730 views

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

This topic has been closed for replies.

1 reply

Inspiring
May 17, 2012

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

taunntAuthor
Inspiring
May 17, 2012

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

Inspiring
May 17, 2012

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

}

}