Note that there are some explanatory texts on larger screens.

plurals
  1. POundefined variable Codeigniter and invalid argument supplied foreach read database
    primarykey
    data
    text
    <p>I was following the <a href="http://www.papatlimo.com/2011/09/simple-crud-with-codeigniter.html" rel="nofollow">instruction</a> to get the entire record from table, and load them into html table. this is the model</p> <pre><code>private $namatabel; public function __construct() { parent::__construct(); $namatabel='ms_kategori_material'; } function read() { $sql = $this-&gt;db-&gt;get($this-&gt;namatabel); if($sql-&gt;num_rows() &gt; 0) { foreach($sql-&gt;result() as $row) { $data[] = $row; } return $data; } else { return null; } } </code></pre> <p>then use the <code>read()</code> function on controller</p> <pre><code>public function __construct() { parent::__construct(); $this-&gt;load-&gt;model('m_kategorimaterial'); } function index() { $data['c_row'] = $this-&gt;m_kategorimaterial-&gt;read(); //pass the c_row into the views $this-&gt;load-&gt;view('v/vkategorimaterial', $data); } </code></pre> <p>to display them on the views</p> <pre><code>&lt;?php $no = 1; foreach ($c_row as $row) { ?&gt; &lt;tr id="row"&gt; &lt;td id="no"&gt;&lt;?php echo $no;?&gt;&lt;/td&gt; &lt;td id="judul"&gt;&lt;?php echo $row-&gt;Kode_Kategori_Material_Jasa;?&gt;&lt;/td&gt; &lt;td id="kategori"&gt;&lt;?php echo $row-&gt;Nama_Material_Jasa;?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php $no++; } ?&gt; </code></pre> <p>but then I got an error saying, undefined variable <code>c_row</code> and invalid argument supplied <code>foreach()</code>. I thought I have sent the <code>c_row</code> variable through the <code>c_kategorimaterial/index</code> and copy pasting <code>foreach</code> statement. what went wrong ? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload