Forum Moderators: coopster

Message Too Old, No Replies

Product Catalog

         

wfernley

8:57 pm on Mar 31, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I was wondering what a good design template is for designing a product catalog with PHP and MySQL.

I will have roughly 50 products, 5 Catagories with 3 Sub-Catagories each. I was curious what the most effective way is to organize these objects.

I have seen one way where each entry in the database had two values the first being the main catagory id and the second being the sub catagory id. Then in PHP it just puts them in the proper catagories using those two id's. Is that the most effective way?

Sorry if this sounds confusing, it is hard to explain considering I don't have much experience making a product catalog in PHP.

Thanks for your help :)

Wes

webwit

10:20 pm on Mar 31, 2004 (gmt 0)

10+ Year Member



I would try to somehow organize all 50 items with only one variable deep, using just 1 id=. You may have to hard code the first level of category selection pages to do this, but it helps the search engines index you properly.

I have a few hundred items with just one variable.

This is just my opinion. :)

killswitch

11:44 pm on Mar 31, 2004 (gmt 0)

10+ Year Member



If you did something like using a number for the categories and subcategories, it would be possible to use mysql to find them using a single variable in the query string. I prefer to use category names in the table instead of numbers but it should work fine either way (you will want to have a way to link the numbers with the names, possibly in the php script).

example:
page: [url.com...] <- Main category 5, sub category 3.

$cat = $_GET['cat'];
$maincat = $cat{0};
$subcat = $cat{1};

SELECT * FROM products WHERE maincat='$maincat' AND subcat='$subcat';

You could do this many ways, how you decide to do it should be whatever way makes sense to you. I would recommend setting an auto increment field for the first column and making it a primary key as well. This way you will always have a unique value should you want to access a specific item in the table.

CREATE TABLE tblname(id INTEGER AUTO_INCREMENT NOT NULL, PRIMARY KEY(id), maincat INTEGER, subcat INTEGER... and so on.

Don't use my code as it is; it is just as an example of how you might do it and does not have any of the normal error checking you would use for $_GET data.