Jump to content

Organizing Categories


Kay1021

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/104259-organizing-categories/
Share on other sites

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. =)

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.