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
https://forums.phpfreaks.com/topic/167261-solved-too-many-tables/
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'

 

 

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.