CodeIgniter Forums
codeigniter - Mysql: Invalid argument supplied for foreach() - 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: codeigniter - Mysql: Invalid argument supplied for foreach() (/showthread.php?tid=58617)



codeigniter - Mysql: Invalid argument supplied for foreach() - El Forum - 06-30-2013

[eluser]Unknown[/eluser]
Code:
function countSv_AV_total(){

    $this->db->flush_cache();
    $this->db->start_cache();

   $sql = "select Verzekeringen.naam,\n"
    . " count(*) total,\n"
    . " sum(case when (Age <= 18) then 1 else 0 end) Age18,\n"
    . " sum(case when (Age BETWEEN 19 AND 30) then 1 else 0 end) Age19,\n"
    . " sum(case when (Age BETWEEN 31 AND 50) then 1 else 0 end) Age30,\n"
    . " sum(case when (Age BETWEEN 51 AND 69) then 1 else 0 end) Age50,\n"
    . " sum(case when (Age >= 70) then 1 else 0 end) Age70\n"
    . " from customers\n"
    . " INNER JOIN Verzekeringen\n"
    . " ON customers.AV=Verzekeringen.verzekeringcode\n"
    . " AND Label =1\n"
    . " group by Verzekeringen.naam LIMIT 0, 30 ";

$this->db->query($sql);

    echo $this->db->last_query().'<br />';

    return $this->db->count_all_results('customers','Verzekeringen');
    $this->db->flush_cache();

}

I'm using this SQL and in the Mysql workbench it's given the right output. Now I want this to get this to the codeigniter Table class.

I get an error while foreach is not recieving data:

A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: views/welcome_message.php

Line Number: 178

Can somebody provide an solution. Thanks in advance