Database joins, views, etc. |
[eluser]www07[/eluser]
Beginner question: Here is a function in my Hotel controller that is supposed to take one hotel out of the database, and show its information along with the island that the hotel is on: Code: function test2() How do I send that to the view? I was using this snippet earlier, based on the video tutorials, but there is no $data in the above function: Code: $this->load->view('test2_view',$data); What is the difference between $query and $data? I've spent hours reading through the manual and experimenting but I haven't been able to get it to work.
[eluser]Michael Wales[/eluser]
Code: $query = $this->db Code: <html>
[eluser]xwero[/eluser]
The $data variable is an associative array that allows you to fill the variables in your view file. The $query variable is an object that holds a database result. You can change it into an array using Code: $query->result_array()/*or*/$query->row_array()
[eluser]www07[/eluser]
Thanks for the quick reply. How do I tell it what view to use? This is my current function: Code: function test2() This is my view (test2_view): Code: <p><?=$hotel->name;?></p> I'm getting errors like: Message: Undefined variable: query Message: Trying to get property of non-object etc. Thanks
[eluser]xwero[/eluser]
Code: function test2()
[eluser]Michael Wales[/eluser]
Code: function test2()
[eluser]mistress_shiira[/eluser]
hi guys! 1. do u have any links to resources which i can read on regarding $this->uri->segment()? 2. actually,im recoding some of my earlier projects to CI and i admit im kinda fuzzy yet on how CI works and all.when i have multiple pages like index,main,results etc. where every page has a different set of data used,would it mean creating different set of models and controller for every page? this is just to clarify though.still experimenting on stuff here. thanks a lot!
[eluser]xwero[/eluser]
[quote author="mistress_shiira" date="1194855117"]hi guys! 1. do u have any links to resources which i can read on regarding $this->uri->segment()? [/quote] uri library Don't forget the uri->uri_to_assoc method to mimic get key-value pairs. [quote author="mistress_shiira" date="1194855117"]2. actually,im recoding some of my earlier projects to CI and i admit im kinda fuzzy yet on how CI works and all.when i have multiple pages like index,main,results etc. where every page has a different set of data used,would it mean creating different set of models and controller for every page? this is just to clarify though.still experimenting on stuff here. thanks a lot![/quote] It depends on how big your site it. If you have a site smaller than ten pages you could put it all in one controller and model. If the site gets bigger it's best to split up the controllers and models by similar functionality. |
Welcome Guest, Not a member yet? Register Sign In |