Codeigniter has a error with foreach loop
<p>my problem is that, when i try to get a product detail from the table, i click on the product's name and it will lead me to product_detail, but when i run i show the problem is: </p>

<blockquote>
  <p>Invalid argument supplied for foreach()</p>
</blockquote>

<p>Can you have a look and tell me what can i do to solve this problem?
this is my view:</p>

<pre><code>&lt;?php foreach ($prod_detail as $ud) { }?&gt;
&lt;form method="POST" name="fr_update"&gt;
&lt;input type="hidden" name="id_sp" value="&lt;?php echo $ud-&gt;id_sp; ?&gt;"&gt;
&lt;div class="row" style="margin-bottom: 10px"&gt;
&lt;div class="col-md-2"&gt;
    &lt;p&gt;Tên sản phẩm&lt;/p&gt;
&lt;/div&gt;
&lt;div class="col-md-4"&gt;
    &lt;input type="text" class="form-control" style="max-width: 365px;" name="ten_sp" readonly value="&lt;?php echo $ud-&gt;ten_sp;?&gt;"&gt;

&lt;/div&gt;
&lt;div class="col-md-2"&gt;
    &lt;p&gt;Ngày sản xuất:&lt;/p&gt;
&lt;/div&gt;
&lt;div class="col-md-4" style="padding-left: 0px"&gt;
    &lt;input align="left" type="date" class="form-control" style="max-width: 365px;" name="ngay_sx" readonly value="&lt;?php echo $ud-&gt;ngay_sx;?&gt;"/&gt;  
&lt;/div&gt;
</code></pre>

<p>    </p>

<p>And this is my controller</p>

<pre><code>function prod_detail($id_sp){
    $data['main_content'] = 'backend/home/manproduct/prod_detail_view';
    $this-&gt;load-&gt;model('product_model');
    $data['prod_detail'] = $this-&gt;product_model-&gt;getProdDetailByProdId($id_sp);
    $data['rows']= $this-&gt;membership_model-&gt;getUserData();
    $data['row']= $this-&gt;product_model-&gt;getProdData();
    $this-&gt;load-&gt;view('includes/admin/template', $data);
}
</code></pre>

<p>And this is my product_model</p>

<pre><code>function getProdDetailByProdId($ten_sp){
    $this-&gt;db-&gt;where('ten_sp', $ten_sp);
    $query = $this-&gt;db-&gt;get('products');
    if ($query-&gt;num_rows() == 1) {
        $data = $query-&gt;row();
        return $data-&gt;$id_sp;
    }
}
function getProdData(){
    $this-&gt;db-&gt;where('ten_sp', $ten_sp);
    $query = $this-&gt;db-&gt;get('products');
    if($query-&gt;num_rows()&gt;0){
        foreach ($query-&gt;result() as $row){
            $data[]=$row;
        }
        return $data;
    }
}
</code></pre>