Forum Moderators: coopster
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
I have a few hundred items with just one variable.
This is just my opinion. :)
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.