Skip to main content
Inspiring
May 29, 2010
Question

alternatives to display 3x3 grid of merchandise

  • May 29, 2010
  • 1 reply
  • 516 views

so I was looking through Ben Forta's code for their merchDisplay custom tag from the Web Application Construction Kit CF8  and was surprised so see they perform a select / where clause on every item of merchandise displayed on the page.

Effectively they do this on the page that displays merchandise

<cfquery getMerch cachedwithin 0,1,0,0>

select *

from merchanidse

</cfquery>

<cfloop query getMerch>

   <cf_MerchDisplay merchID=#merchandiseID#>

</cfloop>

------------------------------------------------------------------------

the <cf_MerchDisplay> custom tag has this code in it

<cfquery name="getMerch" datasource="#APPLICATION.dataSource#" cachedWithin="#createTimeSpan(0,1,0,0)#">

SELECT *

FROM 00_merchandise

WHERE merchandise_ID = #ATTRIBUTES.merchID#

</cfquery>

<cfoutput>

     #merchandise_title#

</cfoutput>

My question is, doesn't performing an individual select / where on each item of merchandise impact performance ? Or because it's cached, does it not matter ?

My alternative is to not have the custom tag and to just use the initial select query to <cfoutput>merchandise_title(1), merchandise_title(2), merchandise_title(3) etc... ?

This topic has been closed for replies.

1 reply

Inspiring
May 31, 2010

Is that really the code from the CFWACK?  Dear god.

Obviously (?) one should neither be doing SELECT *, nor should - as you surmise - be looping over one query, using data from it to call another query per row.  That's really really poor practice.  I don't care whether the code's been simplified to demonstrate some tangential technique, there's no excuse for encouraging coding like that, especially to an unwitting newbie audience, which is the audience of those books.

Whoever wrote that code - IMO - should be shot.

--

Adam