![]() |
help with query - 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: help with query (/showthread.php?tid=12672) |
help with query - El Forum - 10-27-2008 [eluser]Fenix[/eluser] I am trying to pull records from a database and pass the results from a model into a controller. what is the best way to do this? i know i am doing this wrong right now so if somebody could point me in the right direction, that would be great. my model (there is a field in the database for each of the items in the array): Code: function get_assets() my controller: Code: function view_assets() help with query - El Forum - 10-27-2008 [eluser]sl3dg3hamm3r[/eluser] I don't see any need to fill first your $asset-array. You could directly return $Q and pass it to your view. Besides, you override $asset with each iteration. help with query - El Forum - 10-27-2008 [eluser]Fenix[/eluser] so if my model is like this: Code: function get_assets() how would i pass it from my controller to my view and how would i iterate through it to put each record into a table? an example would help a lot, thanks. help with query - El Forum - 10-27-2008 [eluser]iainco[/eluser] Code: class Assets_Model extends Model Code: class Assets_Controller extends Controller assets.php view Code: foreach($assets as $asset) Very crude example but that is how I would go about printing out each asset_id. (Not sure if you need to use the free_result function or if codeigniter takes care of that sort of thing for you) help with query - El Forum - 10-27-2008 [eluser]Fenix[/eluser] thanks, i'll give this a try ![]() help with query - El Forum - 10-27-2008 [eluser]iainco[/eluser] If you run into problems it might be because I usually use the "result_array" method which would mean changing "return $this->db->get('assets')->result();" to "return $this->db->get('assets')->result_array();" and in the view changing "<?=$asset->asset_id?>" to "<?=$asset['asset_id']?>". PHP's print_r function is helpful when figuring out what is contained in result sets. |