How to fetch multy records - 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: How to fetch multy records (/showthread.php?tid=53996) |
How to fetch multy records - El Forum - 08-17-2012 [eluser]Ayelius Maximous[/eluser] Hi guys. I have a table to store Categories and a page to add category. in the add category page I have to display categories too. Controller : Code: class Products extends CI_Controller { Model : Code: class Categories_Model extends CI_Model { View : Code: <table cellspacing=0 cellpadding=9 width='50%' > it just display one record, not all of them. what have I to do ? How to fetch multy records - El Forum - 08-17-2012 [eluser]DarkManX[/eluser] Create a controller which has 2 Methods to display all categories & to add new category. You can add a form to the displaying view for new categories, that will send a request to the adding method. After the validation and insert into db you just redirect to the display site. How to fetch multy records - El Forum - 08-17-2012 [eluser]Ayelius Maximous[/eluser] my problem is how to fetch more than one record. How to fetch multy records - El Forum - 08-17-2012 [eluser]DarkManX[/eluser] Well, thats the smallest problem you got i think. I guess you didnt understand the mvc-concept. result_array() returns you all the results in an array. You dont output any stuff in der model btw. The model suposed to give data from the database to the controller that requested certain data. This controller will give the information to the view (stil no html output happened) and finally the view will output the whole stuff. How to fetch multy records - El Forum - 08-17-2012 [eluser]CroNiX[/eluser] You already are fetching more than 1 record. Just after you echo out your title/description in that loop, you return $row, which is only a single result created while looping over your result set. Try returning the whole result set instead. Code: return $query->result_array(); How to fetch multy records - El Forum - 08-17-2012 [eluser]Ayelius Maximous[/eluser] thanks CroNiX, I did it and I got error : A PHP Error was encountered Severity: Notice Message: Trying to get property of non-object Filename: Admin/Categories.php Line Number: 14 what have I to write for controller and view ? How to fetch multy records - El Forum - 08-17-2012 [eluser]CroNiX[/eluser] Because when you return result_array(), it's an array, not an object. Change it to return $query->result() if you want an object. also, in your view, you will want to loop over $categories Code: <?php foreach($categories as $category): ?> How to fetch multy records - El Forum - 08-17-2012 [eluser]Ayelius Maximous[/eluser] Really thanks dear CroNiX. it works. I really thank you for your help :X |