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:
Invalid argument supplied for foreach()
Can you have a look and tell me what can i do to solve this problem? this is my view:
<?php foreach ($prod_detail as $ud) { }?>
<form method="POST" name="fr_update">
<input type="hidden" name="id_sp" value="<?php echo $ud->id_sp; ?>">
<div class="row" style="margin-bottom: 10px">
<div class="col-md-2">
<p>Tên sản phẩm</p>
</div>
<div class="col-md-4">
<input type="text" class="form-control" style="max-width: 365px;" name="ten_sp" readonly value="<?php echo $ud->ten_sp;?>">
</div>
<div class="col-md-2">
<p>Ngày sản xuất:</p>
</div>
<div class="col-md-4" style="padding-left: 0px">
<input align="left" type="date" class="form-control" style="max-width: 365px;" name="ngay_sx" readonly value="<?php echo $ud->ngay_sx;?>"/>
</div>
And this is my controller
function prod_detail($id_sp){
$data['main_content'] = 'backend/home/manproduct/prod_detail_view';
$this->load->model('product_model');
$data['prod_detail'] = $this->product_model->getProdDetailByProdId($id_sp);
$data['rows']= $this->membership_model->getUserData();
$data['row']= $this->product_model->getProdData();
$this->load->view('includes/admin/template', $data);
}
And this is my product_model
function getProdDetailByProdId($ten_sp){
$this->db->where('ten_sp', $ten_sp);
$query = $this->db->get('products');
if ($query->num_rows() == 1) {
$data = $query->row();
return $data->$id_sp;
}
}
function getProdData(){
$this->db->where('ten_sp', $ten_sp);
$query = $this->db->get('products');
if($query->num_rows()>0){
foreach ($query->result() as $row){
$data[]=$row;
}
return $data;
}
}