Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

check box Coldfusion 9 question

Explorer ,
May 17, 2012 May 17, 2012

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

649
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 17, 2012 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 17, 2012 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 17, 2012 May 17, 2012
LATEST

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

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources