![]() |
This page isn’t working using while loop. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: This page isn’t working using while loop. (/showthread.php?tid=69443) |
This page isn’t working using while loop. - nadeem14375 - 11-23-2017 hi all, I have a strange problem in my application. unable to loop through an array. here my code: Controller: Code: public function rep_fee_invoice_4class() Model: Code: public function get_fee_invoice_4class($data){ View: Code: <?php RE: This page isn’t working using while loop. - Wouter60 - 11-24-2017 I think the problem is in your model. It has a for (... ) loop, to iterate through the students that where found in the query with the class_condition. But in the end, your model only returns the result for the very last iteration. A good way to detect what your model is returning, is to put this code in your controller after you called the model: PHP Code: echo '<pre>'; Take a good look at the output. By the way, running queries in CI can be done so much easier than what you are doing. Let me give you an example: PHP Code: $this->db If you understand that, you can try to let your model get the payment results in one single query, using the JOIN statement: PHP Code: $this->db This query will return an array of records. Each record will have all the fields form the users table, and some fields from the payments table. If no records match the conditions, it will return an empty array. Good luck. RE: This page isn’t working using while loop. - nadeem14375 - 11-24-2017 Hi Wouter60 , Thanks for your reply. Can you tell me where and how my model iterate for all student in a class and return the last result? I want to return all the records by unable to do so. I considered your query writing and will convert all these to that, I new so, following the code where I found here and there. RE: This page isn’t working using while loop. - nadeem14375 - 11-24-2017 Thanks dear, Found the mistake, I needed to store the values in an array with in the for loop and then out of the loop return that array. { for () { ... ... ... $result_array[] = $query->result_array(); //$this->db->get()->result() } return $result_array; } |