![]() |
Need help returning single row from database - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Need help returning single row from database (/showthread.php?tid=42656) Pages:
1
2
|
Need help returning single row from database - El Forum - 06-14-2011 [eluser]blinger2008[/eluser] Hi, I am having trouble returning just a single row from the database after a user clicks on a person's name. I want it to go to the page with all his information on it. I can get it to go to that page, but it is returning all the rows. If you could help me, I'd appreciate it. Model: Code: function get_records(){ Controller Code: function person(){ View Code: <?php if(isset($records)) : foreach($records as $row) :?> Need help returning single row from database - El Forum - 06-14-2011 [eluser]JHackamack[/eluser] What you have is a good example of how to list out all people in your database, try this for individual people: (replace $this->db->where('id') with your id column name Code: function get_record($id){ Code: function person(){ Code: <?php if(isset($records)) : foreach($records as $row) :?> This is all a very basic idea to get you heading in the right direction. Let me know if you have any problems. Need help returning single row from database - El Forum - 06-14-2011 [eluser]JHackamack[/eluser] That href should be: site_url('index.php/people/person'.$row->id) Need help returning single row from database - El Forum - 06-14-2011 [eluser]blinger2008[/eluser] I put that in there, and it just gave me an array of all the people. Need help returning single row from database - El Forum - 06-14-2011 [eluser]JHackamack[/eluser] You should see an array of all the people, but clicking on them should give you the individual person's information Need help returning single row from database - El Forum - 06-14-2011 [eluser]blinger2008[/eluser] Yeah, the first page gives me the list of names, and when i click on one of the names, a giant array comes up of everyones info. Code: Array ( [0] => stdClass Object ( [id] => 1 [firstName] => J Gilbert [lastName] => Kaufman [title] => [photo] => images/image.jpg [bio] => This is his bio. This is his bio. This is his bio. This is his bio. This is his bio. This is his bio. This is his bio. This is his bio. This is his bio. This is his bio. [resume] => This is his resume. This is his resume. This is his resume. This is his resume. This is his resume. This is his resume. This is his resume. This is his resume. This is his resume. This is his resume. This is his resume. This is his resume. This is his resume. This is his resume. ) [1] => stdClass Object ( [id] => 2 [firstName] => Mark [lastName] => Keister [title] => P.E. [photo] => images/image.jpg [bio] => This is his bio. This is his bio. This is his bio. This is his bio. This is his bio. This is his bio. This is his bio. This is his bio. This is his bio. This is his bio. This is his bio. This is his bio. This is his bio. This is his bio. This is his bio. [resume] => This is his resume. This is his resume. This is his resume. This is his resume. This is his resume. This is his resume. This is his resume. This is his resume. This is his resume. This is his resume. This is his resume. This is his resume. This is his resume. This is his resume. ) ) Need help returning single row from database - El Forum - 06-14-2011 [eluser]blinger2008[/eluser] alright i got it but it still spits out as an array, not my person view page. Need help returning single row from database - El Forum - 06-14-2011 [eluser]JHackamack[/eluser] Doh, that was a mistake on my part:] Code: $person=$this->people_model->get_records($this->uri->segment(3)); Code: $person=$this->people_model->get_record($this->uri->segment(3)); Need help returning single row from database - El Forum - 06-14-2011 [eluser]JHackamack[/eluser] Because i had the print_r and then die its spitting out the Array. Just replace that with your view call and you should be good. Need help returning single row from database - El Forum - 06-14-2011 [eluser]blinger2008[/eluser] Yeah I figured out that part but it shows as an array. |