Search code examples
sortingcoldfusionproductcfquery

Sorting values by property from cfoutput


This question for cold fusion programmers, and will be probably asked by me wrongly, because it is open question and actually can't be answered, coz u and me will be in a lack of inf about it :) But still all i need is just a hint or guess about it, so that i can understand and move on to achieve my aim.

So here comes the question: I have the coldfusion output script

<cfquery datasource="#dsn2#">SELECT * FROM PRODUCT WHERE PRODUCT_ID = #PRODUCT_ID#</cfquery>

where some products are displayed, and all i need is to sort them by the property for example is_purchase whose values can be 0 or 1, plus i have a checkbox:

<input type="checkbox" name="is_purchase_stock" value="1" <cfif isdefined("attributes.is_purchase_stock")>checked</cfif> onClick="sayfalama.submit();">

There are actually functions smth like this(is_saleable_stock), u can see it from the all the script of the whole page with products: http://vteam.net.ru/_fr/4/list_prices.cfm

Thank you everyone!


Solution

  • You want ORDER BY, something like this:

    <cfquery datasource="#dsn2#">
        SELECT * FROM PRODUCT 
        WHERE PRODUCT_ID = #PRODUCT_ID#
        ORDER BY is_purchase <cfif StructKeyExists(attributes, "is_purchase_stock")>ASC<cfselse>DESC</cfif>
    </cfquery>
    

    EDIT. This is a reply to the question in a comment:

    <cfquery datasource="#dsn2#">
        SELECT * FROM PRODUCT 
        WHERE PRODUCT_ID = #PRODUCT_ID#
        AND is_purchase = <cfif StructKeyExists(attributes, "is_purchase_stock")>1<cfselse>0</cfif>
    </cfquery>