Not able to display query results in 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: Not able to display query results in View (/showthread.php?tid=19055) |
Not able to display query results in View - El Forum - 05-26-2009 [eluser]chotz[/eluser] I am loading a model in the controller which run the query and gives back the results to controller. I am able to display the results in controller. Then i am passing the $data to view page: $this->load->view('/GameDev/newsad_view',$data); but i am not able to display the results in the view page I am using the following code: <?php echo news_headln; ?> ('news_headln' is my table column stored in the $data array) i also tried <?php echo $data['news_headln'];?> I get the error Undefined variable $data. Please help. -Arun. Not able to display query results in View - El Forum - 05-26-2009 [eluser]chotz[/eluser] Actually i have the following code in my controller Code: $this->load->model('/GameDev/Newsad_model'); In the model class i have: Code: $query=$this->db->get('News_admn'); for some reason i am not able to access $data in View Not able to display query results in View - El Forum - 05-26-2009 [eluser]jedd[/eluser] Hi Arun, No, you don't have $data in your view - only the break down of the contents of the $data array (as it was in the controller). So if you have $data['news_headln'] in your controller, you'd need to have this in your view: Code: echo $news_headln; Note the obvious mistake (not sure if it was a typo) in your code snippet that you posted: Quote:I am using the following code: You definitely need the ol' $ there. Not able to display query results in View - El Forum - 05-26-2009 [eluser]chotz[/eluser] No, that was a typo. But as you can see from the below line of code my results are in 'query' array Code: $data['query']=$this->Newsad_model->get_entries(); query itself will hold an array. So i made the $data hold just my table columns. Code: $data=$this->Newsad_model->get_entries(); and changed my model class to Code: foreach ($query->result() as $row) i.e basically it means $data=$item; Now it works fine Not able to display query results in View - El Forum - 05-26-2009 [eluser]jedd[/eluser] Glad to hear you resolved it. I'd recommend you still assign the return from your model to an element of $data[] - as you are likely to want to have more than just the contents of that one returned value in your view. Re-introducing this indirection, now you have the basics working fine, should be very easy. Not able to display query results in View - El Forum - 05-26-2009 [eluser]chotz[/eluser] ok.You are right. I tried that too. but could not display the elements in view for some reason. Anyway i will figure it out. Thanks for your help! |