![]() |
Passing an Array from Model? - 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: Passing an Array from Model? (/showthread.php?tid=14631) |
Passing an Array from Model? - El Forum - 01-09-2009 [eluser]Solarpitch[/eluser] Hey Guys, I'm a little stuck with the following. I'm calculating a sum of 6 columns in a table, for a specific report. If the report has 2 POS terminals it will return something like... Till 1: €2156.30 Till 2: €1881.20 The problem is its only printing the last value of the result which is Till 2: €1881.20. I must need to handle the array differently? MODEL... Code: //see how many till sthe client has reports for on that date CONTROLLER... Code: function dashboard(){ VIEW... Code: <?=$total_till_takings?> // WHICH WILL ONLY PRINT OUT "Till 2: €1881.20" Passing an Array from Model? - El Forum - 01-09-2009 [eluser]jalalski[/eluser] Yup... that's correct. the line: Code: $data['total_till_takings'] = $this->report_model->total_till_takings('20081209', $row->till); You possibly need this: Code: $data['total_till_takings'][] = $this->report_model->total_till_takings('20081209', $row->till); And then in the view, iterate over it (not just print it out). Passing an Array from Model? - El Forum - 01-09-2009 [eluser]Solarpitch[/eluser] Thanks for the reply Ah I see what you mean. So create a multidimensional array (which are not my strong points) to hold the array being generated from the query. That makes sense. Only, how could I iterate over it in the view. I presume I would need to declare a different array in the view to do this... then loop through it or something? Passing an Array from Model? - El Forum - 01-09-2009 [eluser]Michael Wales[/eluser] Code: <?php foreach ($total_till_takings as $till) { |