Welcome Guest, Not a member yet? Register   Sign In
relational DB
#1

[eluser]matches[/eluser]
Can someone point me to a good relational DB example using codeigniter? I have a blog table and a blog_categories table related to it. I'm just not sure how to display each blog entry with it's related category.

Thanks
#2

[eluser]CroNiX[/eluser]
http://ellislab.com/codeigniter/user-gui...ecord.html

Check out the $this->db->join() section and example.


Or a simple one for you...

BLOG
----
-id
-title
-category_id

CATEGORIES
----------
-id
-name
Code:
$result = $this->db
  ->select('BLOG.title AS title, CATEGORIES.name AS category')
  ->join('CATEGORIES', 'CATEGORIES.id = BLOG.category_id')
  ->get('BLOG')
  ->result_array();

would give you an array of all blog titles along with its category name.




Theme © iAndrew 2016 - Forum software by © MyBB