passing multiple table value by a single function |
[eluser]Paleleaves[/eluser]
Hi, I'm a newbie in CI. I've a view file to display the data from two tables. I managed to get the data from one table and successfully displayed. How can I retrieve data from two tables using a sigle fuction and pass to the view file. Any examples or url in the forum will be really helpful. thanks in advance
[eluser]n0xie[/eluser]
I don't know if you mean you need to join the tables (the tables have some relation to eachother) or that you simply have data stored in seperate tables and want it displayed in one view. If it is the former, you need to do some reading on JOINS. If it is the latter here is a simple example: Code: // controller
[eluser]Paleleaves[/eluser]
Hi, thanks for the reply. But need a little clarification. Here begins; this is the default function index() in the controller. Code: function index () In the view file I've a foreach loop to display the values like this. Code: <?php foreach($query as $item):?> Thank you for spend your time...
[eluser]John_Betong[/eluser]
Here is a BIG KLUDGE to get the job doe and move on to your next problem ![]() Code: <?php Output: Code: .
[eluser]Paleleaves[/eluser]
Hi, Please click on this url to see the schema schema To be more specific I want to combine data from these two tables and pass to a view file. As marked in the schema image; pCat values to come reqType when the view files loads. that's all. thanks
[eluser]Paleleaves[/eluser]
Hi, Thank you very much for the all .. But again stuck on a problem here. Code: $sql['query']= $this->db->query('SELECT * FROM property, ptype WHERE property.reqType = ptype.pID'); I managed to get the information from multiple tables using the above code but need to take the data from a third table along with this. Here is the code I tried but didn't work Code: $sql['query']= $this->db->query('SELECT * FROM property, ptype WHERE property.reqType = ptype.pID, district WHERE property.districtName = district.dID'); Any help will really appreciated!
[eluser]Sinclair[/eluser]
Hi, The selec you need to do to join the tables is: Code: select p.pID, p.reqType, pt.pCat from propery p, ptype pt where p.pID = pt.pID Test the select in PhpMyAdmin or in the tool you use to test the selects. Best Regards,
|
Welcome Guest, Not a member yet? Register Sign In |