I can not pass array loop for view - 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: I can not pass array loop for view (/showthread.php?tid=72114) |
I can not pass array loop for view - n0cturn0 - 11-08-2018 I can not pass array loop for view. each result has one or more positions, however pass in view one position. I used, example: $data['atualiza'] = $totaliza; $this->load->view(myView, $data); this no work, only the first array value; foreach ($vetor as $xvet => $valuevetor) { //TOTALIZA foreach ($complementar->result() as $key => $value) { $totaliza = $this->db->query("select professor, sum(cargah) as soma from cmcg_registros where id_disciplina = '$idsic' and id_professor =". $valuevetor."group by professor")->result(); } foreach ($complementar->result() as $key => $value) { for ($i=0; $i < $key ; $i++) { $consulta = $this->db->query("select professor, id_disciplina, cargah, cargah_local from cmcg_registros where id_disciplina = '$idsic' and id_professor =". $valuevetor."group by professor, id_disciplina, cargah, cargah_local")->result(); } } echo 'TOTALIZA'; echo '<pre>'; print_r($totaliza); echo '</pre>'; echo '<br><hr>'; echo '<pre>'; print_r($consulta); echo '</pre>'; } show TOTALIZA Array ( [0] => stdClass Object ( [professor] => LUIZ AUGUSTO DA SILVA OLIVEIRA [soma] => 90 ) ) Array ( [0] => stdClass Object ( [professor] => LUIZ AUGUSTO DA SILVA OLIVEIRA [id_disciplina] => 19 [cargah] => 5 [cargah_local] => 701 ) [1] => stdClass Object ( [professor] => LUIZ AUGUSTO DA SILVA OLIVEIRA [id_disciplina] => 19 [cargah] => 5 [cargah_local] => 702 ) [2] => stdClass Object ( [professor] => LUIZ AUGUSTO DA SILVA OLIVEIRA [id_disciplina] => 19 [cargah] => 5 [cargah_local] => 703 ) ) Thanks guys! RE: I can not pass array loop for view - Pertti - 11-08-2018 You have loop inside a loop. $consulta will ever have the last value of the last query. PHP Code: foreach ($complementar->result() as $key => $value) { As simple fix you can keep most of the code logic, but add results to existing persistent array: PHP Code: $consulta = []; I would suggest finding a way to get all the data back in a single query tho, if possible, putting queries in couple of nesting loops is very time-consuming. |