Welcome Guest, Not a member yet? Register   Sign In
How to structure effectively news and category relationship ?
#6

(12-09-2014, 08:21 AM)paju89 Wrote: 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

Try something like this:

PHP Code:
$this->db->select('category, news')
 
   ->from('category as t1')
 
   ->where('t1.cat_id'$id)
 
   ->join('news as t2''t1.cat_id = t2.cat_id''LEFT')
 
   ->get(); 
Romanian CodeIgniter Team :: Translations :: Comunity :: Developers
http://www.codeigniter.com.ro
Reply


Messages In This Thread
RE: How to structure effectively news and category relationship ? - by Dracula - 12-09-2014, 08:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB