views:

459

answers:

2

Hi to all.. please help me with this school project for an e-commerce site that im doing ryt now..im a newbie in programming.. here's the scenario..

Im using coldfusion,ms access,dwcs3 How can I dynamically view the products that are base on dynamic category and subcategory? using URL parameters

here is my table on my msaccess

tblcategory

fieldname datatype

category text

subcategory text

tblproduct

ProductID text

Subcategory text

enter code here

Description text

I already show dynamically the category and subcategory but I can't find a solution to show the products base on it's category and subcategory

here's my code

<cfparam name="URL.Category" default="1">

<cfquery name="rs_category" datasource="Database">
SELECT DISTINCT category
FROM tblcategory 
</cfquery>

<cfquery name="rs_subcategory" datasource="Database">
<cfif category eq 1>
SELECT *
FROM tblcategory
<cfelse>
SELECT *
FROM tblcategory
WHERE Category = <cfqueryparam value="#URL.Category#" cfsqltype="cf_sql_clob" maxlength="50"> 
</cfif>
</cfquery>


<body>

 <cfoutput query="rs_category"><a href="dynamic.cfm?category=#rs_category.category#">#rs_category.category#</a><br />
</cfoutput> 


<br />
<cfoutput query="rs_subcategory">#rs_subcategory.Subcategory#<br />
</cfoutput>
<br />


</body>
</html>

sample output

category(dynamic category)

Electrical (when click show electrical subcategory)
Steel
Wood

subcategory(base on the category dynamically show the subcategory)

Phelps dodge  
Metro Wire
Wire Spool

( I need to show the products that are under the same category and subcategory dynamically)

(This is the part that I need to know... so can someone who has experience in cf can help me..)

+1  A: 

It looks like you are headed in the right direction. First, I'd like to say a big bravo for using cfsqlparam. Now, to the advice.

First, always scope url.category when referring to what you are passing in on the command line.

So, if we want to display links to the subcategories, I would probably do something like this:

<cfoutput query="rs_subcategory">
     <a href="dynamic.cfm?category=#urlencodedformat(url.category)#&subcategory=#urlencodedformat(subcategory)#">
         #htmleditfomrat(rs_category.subcategory)#
     </a>
     <br />
</cfoutput>

Now, you need to do the lookup in the db for products based on url.category and url.subcategory, just as you did looking up the subcategories based on category.

If you need additional assistance, please clarify what you need help with, as your question is pretty broad.

Ben Doom
Tomalak
Ben Doom
Err, good catch.
Ben Doom
It will not "break" the ampersand. It will encode it correctly, as *every* ampersand in HTML has to be encoded, *including* those in URLs. The only unencoded ampersands allowed are the ones that start character entities.
Tomalak
Apart from that: You mistakenly use `HTMLEditFormat()` where you should use `URLEncodedFormat()`.
Tomalak
You're right about using urlencodedformat() instead. Look at your first comment, though -- you wrapped the entire href in htmleditformat(). Clearly, we both need more caffeine.
Ben Doom
+1  A: 

Do you want multiple drop downs / select fields to drill down to the product?

If so check out these two links:

http://www.forta.com/blog/index.cfm/2007/5/31/ColdFusion-Ajax-Tutorial-2-Related-Selects

http://forums.forta.com/messages.cfm?threadid=A23B65BE-3048-80A9-EFE12A313B4A9E72

Sam Farmer