codeigniter pass data from view to model and retirve info - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: codeigniter pass data from view to model and retirve info (/showthread.php?tid=36982) |
codeigniter pass data from view to model and retirve info - El Forum - 12-22-2010 [eluser]daka[/eluser] Hier is the thing: I have controller that retrive data from database and pass info to view. In the view I have a loop like this: Code: foreach ($myphotos->result() as $myphoto){ Code: SELECT * FROM users WHERE u_id IN (SELECT u_id FROM p_votes WHERE p_id = 268); Code: foreach ($myphotos->result() as $myphoto){ hier is how: I already have this one: Code: SELECT * FROM photos WHERE p_id NOT IN (SELECT distinct p_id FROM p_votes where u_id = ".$this->session->userdata('u_id').") LIMIT ".$segment_url.", ".$config['per_page']; Hier is the thing: I have controller that retrive data from database and pass info to view. In the view I have a loop like this: foreach ($myphotos->result() as $myphoto){ echo $myphoto->p_id } But in that loop I need to pick up $myphoto->p_id and ask database to retrive me users with this p_id. SELECT * FROM users WHERE u_id IN (SELECT u_id FROM p_votes WHERE p_id = 268); and in: foreach ($myphotos->result() as $myphoto){ echo $myphoto->p_id $this->load->model('m_member'); $users_voted = $this->m_member->getUsersVotedOnImage($myphoto->p_id); foreach ($users_voted->result() as $users){ echo '<div id="voterfooter">voted:<aaaa href="$users->i_id">'.$users->name.</a> } } Ok that was one option that I come up, but there is also other option, but select statment is so complicated! hier is how: I already have this one: SELECT * FROM photos WHERE p_id NOT IN (SELECT distinct p_id FROM p_votes where u_id = ".$this->session->userdata('u_id').") LIMIT ".$segment_url.", ".$config['per_page']; But how to pick up also from users people that voted on that picture and print it in view? Hier is database scheme: Code: CREATE TABLE IF NOT EXISTS `users` ( codeigniter pass data from view to model and retirve info - El Forum - 12-22-2010 [eluser]InsiteFX[/eluser] You should be doing all the checking in your controller not the view! Or let the model handle it. InsiteFX codeigniter pass data from view to model and retirve info - El Forum - 12-23-2010 [eluser]markup2go[/eluser] You probably just need to join the data in the query. Example: Code: $this->db->select('photos.*, users.name as username', FALSE); Then you may not even need to nest a for loop in the view. |