I have a problem with showing 3 latest data from 2 tables with active record in codeigniter.
The tables
- album: id_album, album_name
- photo: id_photo, album_id, photo_name
Current data
Album:
- Car
- Bike
- Airplane
Photo:
- Bike 001
- Bike 002
- Airplane 001
- Airplane 002
- Airplane 003
- Car 001
The condition is how to show the data by 3 latest album with 1 latest photo from each album. Maybe the result like this:
- Car 001,
- Airplane 003,
- Bike 002
My active record in codeigniter:
$this->db->select('album.album_name, album.id_album, photo.id_photo, photo.photo_name);
$this->db->join('album', 'photo.album_id = album.id_album');
$this->db->limit(3);
$this->db->order_by('album.id_album', 'desc');
$this->db->order_by('photo.id_photo', 'desc');
$this->db->group_by('album.album_name');
return $this->db->get($this->table)->result();
If i use the query above, the data will be like this:
- Car 001,
- Airplane 001,
- Bike 001
Any help will be so appreciate