Outputting results from Array? |
[eluser]invision[/eluser]
Hi, I'm a little stuck. I would love some help with this. I want to output the results of a SQL Query into a View. How do I do this? model Code: function get_entries($country = FALSE, $city = FALSE, $category = FALSE) { controller Code: if (!empty($param_3)) { view Code: <h2><?php echo $entries['atitle']; ?></h2> I know for certain that my SQL Query is working. Can anyone explain what I am doing wrong? Many thanks for your time and help.
[eluser]Marcelo Reborn[/eluser]
Why don't you debug $data? Code: if (!empty($param_3)) {
[eluser]invision[/eluser]
Cool. What am I looking for in the output? Here's what I've got: Code: Array
[eluser]Madmartigan1[/eluser]
Try this bud: $this->output->enable_profiler(true); Put that anywhere in your controller. All your queries will be displayed at the bottom of the page.
[eluser]invision[/eluser]
Thank you Madmartigan. It shows 6 queries and they all successfully receive data. Can you explain how I show this data in my View? For instance, if I wanted to show the following data in my View: Code: [cost] => From: £94.00 p/w How do I do this? Many thanks for your help
[eluser]Madmartigan1[/eluser]
Are you simply asking how to send data from a controller to a view? Haven't you done this before? http://ellislab.com/codeigniter/user-gui...views.html
[eluser]invision[/eluser]
Thanks for the quick reply and your patience. In my Controller, I'm currently using: Code: $data['entries'] = $this->Mains->get_entries($param_1, $param_2, $param_3); If I want to display the value of (say) roomclass1 in my View, how do I do this? I have done this before, but for some reason using $roomclass1 doesn't display anything. Am I passing it to the View incorrectly? Thanks again for your help with this.
[eluser]Madmartigan1[/eluser]
Code: $data['entries'] = $this->Mains->get_entries($param_1, $param_2, $param_3); When you send this to your view, it will be stored in an array named $entries. It does not alter the data in any other way. You would work with the array or object as you normally would in plain non-codeigniter PHP.
[eluser]invision[/eluser]
As you can tell I'm pretty new to this. I always presumed you'd do either $data['entries']['roomclass1'] or $entries['roomclass1'] but sadly both don't work. Can you give me any pointers? I'm sure once I get this started, I'll be just fine Many Thanks
[eluser]Madmartigan1[/eluser]
$data[‘entries’][‘roomclass1’] will work in the controller, in the view you want to use $entries[‘roomclass1’], assuming that your array keys are correct. Does this make sense? |
Welcome Guest, Not a member yet? Register Sign In |