S
Simon Harris
Hi All,
I have written a page that generates a site map of all categories and
products within a shopping cart system. It works a treat, apart from being
toooo slooow.
The code is below, can anyone think of a way of generating the same
results,
but more efficiently? There are 1187 categories, 471 products (This may
seem
like an odd ratio, It's structured that way due to the nature of the
business). Categories can hold any number of other categories, and
products.
For info, just running showCatsWithinCat with the call to
showProdsWithinCat
commented out, takes approx 10 seconds. With the products displayed takes
approx 40 seconds!
I was thinking perhaps some TSQL to generate this within SQL server - Not
sure this was speed things up though? Also, I wouldnt know where to start
with TSQL.
Hope some one has a cool idea for this!
Cheers,
Simon.
---------------
'**************************************
'Display Products within given category
'**************************************
sub showProdsWithinCat(CatID)
'Declare Variables
dim mySQL, rsTemp
'Get and loop data
mySQL = "SELECT a.idProduct,a.description,a.descriptionLong,a.details
FROM
products a " &_
"WHERE a.active = -1 AND EXISTS " &_
"(SELECT b.idCategory FROM categories_products b WHERE b.idProduct =
a.idProduct AND b.idCategory = " & CatID & ")"
Response.Write("<ul>")
set rsTemp = openRSexecute(mySQL)
do while not rsTemp.eof
response.write "<li><a href=""" & urlNonSSL & "prodView.asp?idproduct="
&
rsTemp("idProduct") &""">" & rsTemp("description") & "</a><br>" &
rsTemp("description") & "<br>" & rsTemp("descriptionLong") & "<br>" &
rsTemp("details") & "</li>"
rsTemp.movenext:loop
Response.Write("</ul>")
'Close up
call closeRS(rsTemp)
end sub
'**************************************
'Display category tree in bulleted list
'**************************************
sub showCatsWithinCat(CatID)
'Declare variables
dim mySQL, rsTemp
'Get and loop data
mySQL ="SELECT idCategory, categoryDesc, categoryHTMLLong FROM Categories
WHERE (idParentCategory = " & CatID & ");"
Response.Write("<ul>")
set rsTemp = openRSexecute(mySQL)
do while not rsTemp.eof
response.write "<li><a href=""" & urlNonSSL & "prodList.asp?idCategory="
&
rsTemp("idCategory") &""">" & rsTemp("categoryDesc") & "</a><br></li>"
Call showProdsWithinCat(rsTemp("idCategory"))
Call showCatsWithinCat(rsTemp("idCategory"))
rsTemp.movenext:loop
Response.Write("</ul>")
'Close up
call closeRS(rsTemp)
end sub
'**************************************
'Display Site Map
'**************************************
Call showCatsWithinCat(0)
I have written a page that generates a site map of all categories and
products within a shopping cart system. It works a treat, apart from being
toooo slooow.
The code is below, can anyone think of a way of generating the same
results,
but more efficiently? There are 1187 categories, 471 products (This may
seem
like an odd ratio, It's structured that way due to the nature of the
business). Categories can hold any number of other categories, and
products.
For info, just running showCatsWithinCat with the call to
showProdsWithinCat
commented out, takes approx 10 seconds. With the products displayed takes
approx 40 seconds!
I was thinking perhaps some TSQL to generate this within SQL server - Not
sure this was speed things up though? Also, I wouldnt know where to start
with TSQL.
Hope some one has a cool idea for this!
Cheers,
Simon.
---------------
'**************************************
'Display Products within given category
'**************************************
sub showProdsWithinCat(CatID)
'Declare Variables
dim mySQL, rsTemp
'Get and loop data
mySQL = "SELECT a.idProduct,a.description,a.descriptionLong,a.details
FROM
products a " &_
"WHERE a.active = -1 AND EXISTS " &_
"(SELECT b.idCategory FROM categories_products b WHERE b.idProduct =
a.idProduct AND b.idCategory = " & CatID & ")"
Response.Write("<ul>")
set rsTemp = openRSexecute(mySQL)
do while not rsTemp.eof
response.write "<li><a href=""" & urlNonSSL & "prodView.asp?idproduct="
&
rsTemp("idProduct") &""">" & rsTemp("description") & "</a><br>" &
rsTemp("description") & "<br>" & rsTemp("descriptionLong") & "<br>" &
rsTemp("details") & "</li>"
rsTemp.movenext:loop
Response.Write("</ul>")
'Close up
call closeRS(rsTemp)
end sub
'**************************************
'Display category tree in bulleted list
'**************************************
sub showCatsWithinCat(CatID)
'Declare variables
dim mySQL, rsTemp
'Get and loop data
mySQL ="SELECT idCategory, categoryDesc, categoryHTMLLong FROM Categories
WHERE (idParentCategory = " & CatID & ");"
Response.Write("<ul>")
set rsTemp = openRSexecute(mySQL)
do while not rsTemp.eof
response.write "<li><a href=""" & urlNonSSL & "prodList.asp?idCategory="
&
rsTemp("idCategory") &""">" & rsTemp("categoryDesc") & "</a><br></li>"
Call showProdsWithinCat(rsTemp("idCategory"))
Call showCatsWithinCat(rsTemp("idCategory"))
rsTemp.movenext:loop
Response.Write("</ul>")
'Close up
call closeRS(rsTemp)
end sub
'**************************************
'Display Site Map
'**************************************
Call showCatsWithinCat(0)