CodeIgniter Forums

Full Version: does ci support relational db
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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.

El Forum

[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.

El Forum

[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();

El Forum

[eluser]dsi[/eluser]
thank u all

El Forum

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