Kay1021 Posted May 5, 2008 Share Posted May 5, 2008 I have a bit of a puzzle I'm trying to figure out....I was wondering if anyone might be able to help me sort it out....or in the direction. I have 11 main categories and about 185 sub categories that may appear in one or more main category. In the sub categories are companies. The user will enter the site and search by postal code. I want to only show the categories & sub categories that have a company with that postal code. I'm just having trouble figuring out how i should set up my databases. Any guidance or help would be greatly appreciated... I hope this made some sense. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/104259-organizing-categories/ Share on other sites More sharing options...
DarkWater Posted May 5, 2008 Share Posted May 5, 2008 categories: category_id int not null auto_incrementing category_name varchar(50) not null sub_cats: subcategory_id int not null auto_incrementing subcategory_name varchar(50) not null any other info cat_relation: category_id int not null subcategory_id int not null To insert a sub category into multiple categories, you make several rows in the cat_relation table using mysql_insert_id to get the last inserted ID when making the category. =) Quote Link to comment https://forums.phpfreaks.com/topic/104259-organizing-categories/#findComment-533738 Share on other sites More sharing options...
Kay1021 Posted May 6, 2008 Author Share Posted May 6, 2008 ok i have the category table with my 11 categories and my sub category table In the cat_relation table does anything go into those two fields...or how do you get the other info into them and im a little confused about the last part Quote Link to comment https://forums.phpfreaks.com/topic/104259-organizing-categories/#findComment-534523 Share on other sites More sharing options...
Daniel0 Posted May 6, 2008 Share Posted May 6, 2008 It would hold parent-child information. Instead of DarkWater's suggested database layout, I'd just remove the sub_cats table and have both category_id and subcategory_id in the cat_relation table reference an entry in the categories table. Quote Link to comment https://forums.phpfreaks.com/topic/104259-organizing-categories/#findComment-534541 Share on other sites More sharing options...
Kay1021 Posted May 9, 2008 Author Share Posted May 9, 2008 thanks for the help i just had a question....when you like the select * from statements how do you get that information to output... do you use echo or need a an if or while statement? Quote Link to comment https://forums.phpfreaks.com/topic/104259-organizing-categories/#findComment-536706 Share on other sites More sharing options...
Daniel0 Posted May 9, 2008 Share Posted May 9, 2008 You'd loop through it using e.g. a while loop. Example: <?php $db = new PDO('mysql:dbname=test;host=localhost', 'root', ''); $result = $db->query('something'); while($row = $result->fetch()) { // do stuff } // or foreach($result->fetchAll() as $row) { // do stuff } ?> I used PDO here. Quote Link to comment https://forums.phpfreaks.com/topic/104259-organizing-categories/#findComment-536711 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.