[eluser]Kamy[/eluser]
Hi:
I'm working on a musician website , who has many albums and songs. Many songs appear in many albums, for example "Greatest Hits"
To manage that I have created 3 tables: albums, songs, songs_albums.
Albums has all the Album info like: title, year released, etc....
Songs has all the songs info like: title, length, lyrics...
songs_albums is where the relationship between albums and songs defined.
It has albumid, songid, displayOrder
I can successfully retrieve and display all the songs for 1 album with a statement like this:
Code:
function Albums()
{
$this->load->scaffolding('songs');
$this->load->helper("url");
$this->template->set('blogDisplay', '1');
$this->template->set('nav', 'Discography');
$this->db->select('*');
$this->db->from('songs_albums');
$this->db->join('albums', 'albums.albumid=songs_albums.albumid');
$this->db->join('songs', 'songs.songid=songs_albums.songid');
$this->db->where('songs_albums.albumid', $this->uri->segment(3));
$this->db->order_by("songs_albums.displayOrder", "asc");
$data['query2'] = $this->db->get();
$this->template->load('template', 'albums_view',$data);
}
Now we need a new page, where I have to display each the Album title with corresponding songs.
{from this point I'm lost}
Do I have to run a query within the query? Should I use DISTINCT?
I did tweak the code a bit to this:
Code:
function Downloads()
{
$this->load->scaffolding('songs');
$this->load->helper("url");
$this->template->set('blogDisplay', '1');
$this->template->set('nav', 'Discography');
$query = $this->db->query("SELECT * FROM albums");
foreach($query->result_array() as $row99)
{
$this->db->select('*');
$this->db->from('songs_albums');
$this->db->join('albums', 'albums.albumid=songs_albums.albumid');
$this->db->join('songs', 'songs.songid=songs_albums.songid');
$this->db->where('songs_albums.albumid', $row99["albumid"]);
$this->db->order_by("songs_albums.displayOrder", "asc");
$data['query2'] = $this->db->get();
}
$this->template->load('template', 'downloads_view',$data);
}
But that only displays one album.....
please help.....