Jump to content

[SOLVED] too many tables?


asmon

Recommended Posts

i have a table of categories and a table of subjects.

a subject can be related to more than one category

therefore i created a 3rd table: category_subject

with the relationship between them.

then to select it, i'm doing something like this

 

    static function select_subjects_by_cat_id($selection, $current_id) {
        global $db;   
        $new_arr = array();    
        $query = $db->sql_query("select $selection from $db->subjects_table join $db->subject_category on
        $db->subject_category.subj_id = $db->subjects_table.id 
        where $db->subject_category.cat_id = $current_id");  
        while ($result = $db->sql_fetch_array($query)) {
            $new_arr[] = $result;
        }
        return $new_arr;   
    }

 

it works great but then i have to relate many users to one subject. so again, i have to

make another table: user_subjects.

my site has many relations therefore i'm ending up with many tables

is it fine doing it this way or there's a better solution?

Link to comment
Share on other sites

I don't see why a third table is needed? Somebody set me straight if I'm wrong, but wouldn't it be better to do it this way:

 

Category:

category_id

category_name

 

Subject:

subject_id

subject_name

category_id

 

So, to get all subjects from a specific category, just SELECT * FROM Subject WHERE category_id = '$cat_id'

 

 

Link to comment
Share on other sites

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.