help newbie with query |
It's a couple of weeks that I'm playing with CodeIgniter in my spare time, I like it, but I'm totally newbie so please .... be patient !
In my DB I have 2 tables 'authors' and 'songs' CREATE TABLE `authors`(`Anome` varchar(160) ... CREATE TABLE `songs` (`Bnome` varchar(160) , `Bautore` varchar(160) .... in "views/myappl/index.php" I list all the authors <a href="<?php echo site_url('myapp/indexAutore'); ?>">lista indexAutore</a> "views/myappl/indexAutore.php" contains foreach ($authors as $authors_item): $autore=$authors_item['Anome']; echo "<p><a href=". site_url('myapp/braniXautore/'.rawurlencode($autore)); echo ">view detail</a></p>"; endforeach; when the user click on an author (href) I would like to list all his songs (all the songs of 'Anome' in authors <=> Bautore in songs) in "views/myappl/braniXautore.php" there is foreach ($songs as $songs_item): $brano=$songs_item['Bnome']; echo $brano; endforeach; Unfortunately 'Bnome' appears as null, so all the songs of all the authors are listed :-( What am I missing ? What am I doing worng ? THANKS for your PATIENCE !!! the model contais: ------------------------------------------------------------------------------------------ public function get_authorsBrani($Bnome = FALSE) { if ($Bnome === FALSE) { $query = $this->db->get('songs'); return $query->result_array(); } $Bnome=urldecode($Bnome); $query = $this->db->get_where('songs', array('Bnome' => $Bnome)); return $query->row_array(); } ------------------------------------------------------------------------------------------ in routes there is: ------------------------------------------------------------------------------------------ $route['myappl/indexAutore'] = 'songs/indexAutore'; $route['myappl/braniXautore'] = 'songs/braniXautore/$1'; $route['myappl/braniXautore/(:any)'] = 'songs/braniXautore/$1'; $route['myappl/(:any)'] = 'songs/braniXutore/$1'; $route['myappl'] = 'songs'; ------------------------------------------------------------------------------------------
1. In models, You should separate the methods where you get the single item and multiple items. For example it is better to have a method to get specific song, and another method to get multiple songs.
2. Example of method to get songs: //replace column names for your needs. PHP Code: public function get_songs($filter, $order = array('column' =>'released_at', 'dir' => 'desc')){ if in your model you did not encode url you should not decode it in model.
|
Welcome Guest, Not a member yet? Register Sign In |