invalid foreach() expecting to show no data if null in Codeigniter <p>I was expecting view to show message 'no data found' when my query is returning null value but im getting error message: Invalid argument supplied for foreach() <p>Here's the controller code:</p> <pre><code>public function index() { $ctki = $this-&gt;ctki_model-&gt;get_all_ctki_data(); if ( !empty($ctki) ) { $this-&gt;data['ctkiData'] = $ctki; } else { $this-&gt;data['ctkiData'] = 'Tidak ada data CTKI.'; } $this-&gt;load-&gt;view($this-&gt;layout, $this-&gt;data); } </code></pre> <p><p>Here's the view code:</p> <pre><code>&lt;table class="table table-striped table-bordered table-hover table-condensed"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;No&lt;/th&gt; &lt;th&gt;Nama Lengkap&lt;/th&gt; &lt;th&gt;Jenis Kelamin&lt;/th&gt; &lt;th&gt;No KTP&lt;/th&gt; &lt;th&gt;No Passport&lt;/th&gt; &lt;th&gt;Kota&lt;/th&gt; &lt;th&gt;No Telepon&lt;/th&gt; &lt;th&gt;No HP&lt;/th&gt; &lt;th&gt;Aksi&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;?php foreach($ctkiData as $row): ?&gt; &lt;?php // Link edit, hapus, cetak $link_edit = anchor('program/administrasi/edit/'.$row-&gt;ID_CTKI, '&lt;span class="glyphicon glyphicon-edit"&gt;&lt;/span&gt;', array('title' =&gt; 'Edit')); $link_hapus = anchor('program/administrasi/hapus/'.$row-&gt;ID_CTKI,'&lt;span class="glyphicon glyphicon-trash"&gt;&lt;/span&gt;', array('title' =&gt; 'Hapus', 'data-confirm' =&gt; 'Anda yakin akan menghapus data ini?')); ?&gt; &lt;tr&gt; &lt;td&gt;&lt;?php echo ++$no ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $row-&gt;Username ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $row-&gt;Nama_Lengkap_User ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $row-&gt;No_Telepon ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $row-&gt;No_HP ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $row-&gt;Level ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo format_is_blokir($row-&gt;Status_Blokir) ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $link_edit.'&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'.$link_hapus ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php endforeach ?&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre>