DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   ColdFusion (http://www.daniweb.com/forums/forum19.html)
-   -   Cleaning up my code. (http://www.daniweb.com/forums/thread79096.html)

morestar May 23rd, 2007 12:45 pm
Cleaning up my code.
 
Hi everyone. This is my first time here. I thank everyone for their help and support.

I don't have much of a problem but I have some code that I want to clean up and I'm fairly new at coldfusion. I believe there is a way I can clean up my code with respect to this one function I have and/or make the function run faster. I don't even know if it's actually a function but here it is:

<!--- Set list of items to display for this category --->
<cfset getlist = ArrayNew(1)>
<cfset str = "">   
<cfset x = 1>

<cfquery name="item" datasource="#request.dsn#">
    select productnum from gift1to100 where gifttype = '#showlist#' and currency = #currency.currency_id#;
</cfquery>
<cfloop query="item">           
    <cfset getlist[x] = #item.productnum#>       
    <cfif x eq item.recordcount>       
        <cfset str = str & getlist[x]>
    <cfelse>
        <cfset str = str & getlist[x] & ",">
    </cfif>
    <cfset x = x + 1>       
</cfloop>
<cfset itemlist = str>

<!--- get items from db --->
<cfquery name="item" datasource="#request.dsn#">
    select productdescription.product_name, product.description_id, product.product_no, productprice.price
    from product, productdescription, productprice
    where
        product.description_id = productdescription.description_id
        and product.product_no = productprice.product_no
        and productprice.currency_id = #currency.currency_id#
        and productprice.franchise_id = 0   
        and (product.product_no = 0<cfloop list="#itemlist#" index="i"> or product.product_no = #i#</cfloop>);
</cfquery>

So basically I have a table with a product number field. My overall desire was to append the product numbers to the 'itemlist' variable and then have each product number taken from another table based on the 'gifttype' and 'currency'.

Is there a faster way? If you need more information please let me know.

Thanks always.


All times are GMT -4. The time now is 8:30 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC