Welcome Guest, Not a member yet? Register   Sign In
does ci support relational db
#1

[eluser]dsi[/eluser]
hi, i m new to ci and i can't figure out how does ci work with relational db. I mean i have 2 tables in db and 1 table has id of another table's content, how do i get another content using that tables id? i have to use loop to echo the content of the 1st table, so can't use another loop, just confused, if u need db structure i can provide.
#2

[eluser]Bart v B[/eluser]
i don't understand youre question.
a relational database has nothing to do with CI or other frameworks.

You want to JOIN two table together, with active Records i gues..

Take a look in the manual Wink
http://ellislab.com/codeigniter/user-gui...ecord.html

Code:
$this->db->select('*');
$this->db->from('blogs');
$this->db->join('comments', 'comments.id = blogs.id');

$query = $this->db->get();

// Produces:
// SELECT * FROM blogs
// JOIN comments ON comments.id = blogs.id


I would not recomend this example, but just play with it.
#3

[eluser]theprodigy[/eluser]
just build your query around it.

Example:
Code:
$this->db->select('u.first_name, u.last_name, a.street, a.city, a.state, a.zip');
$this->db->from('users u');
$this->db->join('addresses a','a.user_id = users.id');
$this->db->where('users.id',$user_id);
$results = $this->db->get();
#4

[eluser]dsi[/eluser]
thank u all
#5

[eluser]Jelmer[/eluser]
You could also try an ORM. Search the forums for DMZ, RapidDataMapper or Doctrine.




Theme © iAndrew 2016 - Forum software by © MyBB