I am looking for an efficient solution to the storage of multiple categories to a single business. What is, is that I have 2 tables (one of the main categories and one with subcategories). In these two tables, of course, each category has a name, a description and an ID (primary key). When this is set up so I only want to save Category_id to the business table and either JOIN them with business_id or run your own query to retrieve the category name. The reason why I wonder so much of this is due. I feel it is unnecessary to have a separate table set up as follows:
maincategory_id | subcategory_id | business_id
where there is a category rates. row. If so unnecessary "many" rows 1000 if businesses have 5 categories.
So what I thought was to write all category_id to one or two separate fields in the business table, separated by "," (comma) and then to run such a small matter to place them nicely in a list or something:
PHP Code:
<?php
$cat = array();
$cat[] = explode(',',$get['category']);
foreach $cat AS $value { ... } // or something like that works
?>
But in connection with the search/appraisal of results, based on the category, where I used this SQL query, I got a problem:
PHP Code:
<?php
$sql = mysql_query('SELECT * FROM businesses WHERE category LIKE %'.$_POST['category_id'].'%');
?>
What is, is that the tabs 9, 19, 29 ... etc / etc. All contain the number 9. What naturally happens is that a business will appear in too many / incorrect result views. Alternative I can write all the names of the categories this field, but I think that also is not so easy.
So what I wonder is how this can be solved - many do the like everywhere, there is certainly a "standard" on it. I reckon that websites like my assignments, and other tender services have not listed one per row. Have searched a bit but can not find anything like that right around the structure/layout.
Does someone have come up with some tips there?
Bookmarks