Select View - 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: Select View (/showthread.php?tid=8833) Pages:
1
2
|
Select View - El Forum - 06-02-2008 [eluser]ealonw[/eluser] hey guys was trying to do a select view but Im not quite sure of how to dosplay that... Can you look at the class below and tell me what im missing? class Contact extends Controller { function index() { $this->load->helper(array('form', 'url')); // Produces: SELECT * FROM mytable $query = $this->db->get('usercomment'); foreach ($query->result() as $row) { echo $row->fname; echo $row->lname; echo $row->email; echo $rom->comment; } $this->load->view('contact_view'); } } Im getting Fatal error: Call to a member function get() on a non-object in /var/www/html/codeigniter/system/application/controllers/contact.php on line 11 Select View - El Forum - 06-02-2008 [eluser]mironcho[/eluser] Is the database library loaded? If not, then load it: Code: class Contact extends Controller { Select View - El Forum - 06-03-2008 [eluser]ealonw[/eluser] Hmmmm... Now im getting a 404.. but the page is there.. Below is the view code.. What am I missing here? <html> <head>Comment View</head> <body> <?php foreach ($query->result() as $row): ?> <?=$row->fname?> <?=$row->lname?> <?=$row->email?> <?=$row->comment?> <?php endforeach;?> </body> </html> Select View - El Forum - 06-03-2008 [eluser]stuffradio[/eluser] Well one thing is that you usually wouldn't do the foreach statement in the controller. Also you need to pass the $query variable to the view. Code: class Contact extends Controller { In your view you go: Code: <html> It should work Select View - El Forum - 06-03-2008 [eluser]ealonw[/eluser] Wow... I still got a 404... This is so simple yet so confusing... What could be missing? **********CONTROLLER********* <?php class Contact extends Controller { function Contact() { parent::Controller(); $this->load->library('database'); $this->load->helper(array('form', 'url')); $this->load->scaffolding('usercomment'); } } function index() { $this->load->helper(array('form', 'url')); // Produces: SELECT * FROM mytable $query = $this->db->get('usercomment'); $this->load->view('contact_view', $query); } *********VIEW******** <html> <head>Comment View</head> <body> <?php foreach ($query->result() as $row): ?> <?=$row->fname?> <?=$row->lname?> <?=$row->email?> <?=$row->comment?> <?php endforeach;?> </body> </html> Select View - El Forum - 06-03-2008 [eluser]ealonw[/eluser] Is there anyone who can help...? Tons of smart folks out there... Who knows what Im missing? Select View - El Forum - 06-03-2008 [eluser]stuffradio[/eluser] You closed the Contact class off really early. Code: **********CONTROLLER********* Also in the View don't you need semicolons after $row->fname, $row->lname, etc.? Select View - El Forum - 06-03-2008 [eluser]ealonw[/eluser] Hello stuff radio... Okay so you say I closed it off early? Can you explain? Select View - El Forum - 06-03-2008 [eluser]ealonw[/eluser] Okay I moved the curly to the end of the class like you had it.... I can now get to the contact_view file... Wow how specific!! I didnt put ( and now Im getting a new error... Fatal error: Call to a member function result() on a non-object in /var/www/html/codeigniter/system/application/views/contact_view.php on line 4 Select View - El Forum - 06-03-2008 [eluser]stuffradio[/eluser] Not too sure why that error comes up... but you don't need to load the helper in each function. Once it's loaded in the function Contacts() you don't need to type it again! |