Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.