How to structure effectively news and category relationship ? |
i have two tables in database
CATEGORY table below if parent id is set to 0 is main category if it is set to any its subcategory cat_id | name | parent_id --------------------------------------- 1 | Electronics | 0 2 | Computer | 1 3 | Computer | 1 NEWS table below id | news_name | news_text | cat_id --------------------------------------- i wonder how to make them related each others via common id ? Any ideas (12-09-2014, 08:21 AM)paju89 Wrote: i have two tables in database Where did my answer go ![]()
Romanian CodeIgniter Team :: Translations :: Comunity :: Developers
http://www.codeigniter.com.ro (12-09-2014, 08:21 AM)paju89 Wrote: i have two tables in database Try something like this: PHP Code: $this->db->select('category, news')
Romanian CodeIgniter Team :: Translations :: Comunity :: Developers
http://www.codeigniter.com.ro
If you just want to join all articles to the associated category you just need a quey like that.
PHP Code: $this->db->from('category') cat_id is the matching key for both tables. |
Welcome Guest, Not a member yet? Register Sign In |