display products on category detail page
I'm trying to display the products within a category on the category detail page (productcategories_Results.php). I have everything working just not sure what the next step is.
I'm trying to display the products within a category on the category detail page (productcategories_Results.php). I have everything working just not sure what the next step is.
There are a couple different approaches that can be used for categories:
1) a product can belong to only one category
2) a product can belong to multiple categories
the basic idea for showing the products in the categopry is to create a recordset that filters the products based on the CategoryID URL Variable.
the specifics of this depend on which approach was used.
If products belong to only one category, there will be a CategoryID column in the products table, create the recordset to filter the Products table using the Category ID column and the CategoryID URL Variable.
If products can belong to more than one category, you will have a linking table and will need to use a joined query, see the following page for more details on joined queries:
http://www.w3schools.com/sql/sql_join.asp
Jason.
Thanks for the reply.
The products will only belong to one category.
Would this be the tutorial to follow?
http://www.webassist.com/community/tutorials/view_tutorial.php?tid=104
I think I made a little progress by using the following ...
SELECT ProductName, ProductCategoryID
FROM products
WHERE ProductCategoryID = colname
... but still curious as to how I get this to dynamically list the products on the page and then link each product to its detail page.
You use the bindings panel to create a display of the products recordset information and add a repeat region around it.
Thanks again for your reply and I apologize for dragging this on, but is my recordset filter correct?
SELECT ProductID, ProductName, ProductCategoryID
FROM products
WHERE ProductCategoryID = colname
After creating the above in the Binding panel, I have the following on the page and nothing is showing ... (I copied the "View Details" link from the products results page.)
<table width="95%" border="0" cellspacing="0" cellpadding="5">
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['ProductName']; ?><?php echo $row_Recordset1['ProductID']; ?><?php echo $row_Recordset1['ProductCategoryID']; ?></td>
<td align="center"><span id="View<?php echo(rawurlencode($row_WADAproducts['ProductID'])); ?>" class="WADATextButton"><a href="products_Detail.php?ProductID=<?php echo(rawurlencode($row_WADAproducts['ProductID'])); ?>">View Details</a></span></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
not enough information to know if the recordset is correct, send a copy of the page please and a ;link where i can see the problem.
so the link to the details page:
productcategories_Detail.php?CategoryID=2
passes the id in a URL variable named:
CategoryID
In your recordset, you have set the filter to use a URL variable named:
ProductCategoryID
edit the recordset and set the filtering section to use the column named ProductCategoryID = to URL variable named CategoryID
FANTASTIC! That did the trick. Thank you so much Jason!!
Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.
These out-of-the-box solutions provide you proven, tested applications that can be up and running now. Build a store, a gallery, or a web-based email solution.