Relative Beginner : Simple problem, I guess...

Hello everyone, i’ll make this brief, as I’m sure its very simple…

I am a designer first and foremost, so php/mySQL coding is relatively new to me, however, I am in the process of building an online store for a small business. I have used a table ‘products’ to hold all my products, with the following structure;

|id|product_name|price|category|description|product_image

I have been able to create a page which shows ALL the products, however, what I would like to do is have a list of categories down one side which, when clicked will go to a page showing all products with that category. My question, do I have to build a separate page for each category, or can I build one page, and carry through the category variable in the URL rather like the actual product view page I have… (i.e /product.php?id=2).

The code that outputs the products on the main store page is as follows;

[php]<?php

$dynamic_list = “”;
$sql = mysql_query(“SELECT * FROM products ORDER BY date_added DESC LIMIT 50”);
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row[“id”];
$product_name = $row[“product_name”];
$price = $row[“price”];
$date_added = strftime("%b %d, %Y", strtotime($row[“date_added”]));
$details = $row[“details”];
$dynamic_list .= ’

'. $product_name .'
£'. $price .'
'. $details .'
View Product
'; } } else { $dynamic_list = "There are no products listed in your store yet"; } mysql_close();

?>[/php]

I apologise if i’m not using the correct terminology, as i said, i’m relatively new to php programming, and have been building this store and a gallery by using bits and bobs from various tutorials around the web and modifying the code to try and figure it all out, learn by doing and all that…

Many thanks in advance!

Joe

Yes you can do that. What you will want to do is add a categories column to your products table. Then select all the categories and output them into links.

[php]

<?php echo $category"; ?>

[/php]

Then at the top of each page you can control the flow of the divs by say

[php]

<?php //Received current page for direction if (isset($_GET['category'])) { $catergory = $_GET['category']; $SetDivs->setPageColumns($category); ?>

[/php]

Then obviously you are going to have to make a SetDivs class which will display and hide certain divs depending on what you want to show.

Sponsor our Newsletter | Privacy Policy | Terms of Service