php - Codeigniter passing data from model to controller -
i new codeigniter .can 1 please me telling how pass $row['main_products_cat_id']; in model 'id'=> 'my id here', in controller. tried many ways failed.
thanks!!!
this model
function cart_product_records($id){ $this->db->from('tbl_sub_products'); $this->db->where('tbl_sub_products.sub_product_id', $id); $query = $this->db->get(); foreach ($query->result_array() $row){ echo $row['main_products_cat_id']; echo $row['sub_product_id']; echo $row['sub_product_name']; echo $row['sub_product_description']; echo $row['sub_product_image']; echo $row['sub_product_price']; } return $query->result(); } this controller
function shopping_cart(){ $id = $this->input->get('id'); if($query = $this->mod_products->cart_product_records($id)){ $data['result'] = array( 'id' => 'my id here', 'qty' => qty here, 'price' => price here, 'name' => 'my product name here' ); } }
first - should not echo data in model - should echo data in view file.
the way data flowing first passing $id controller cart_product_records function in mod_products model. model runs query , gets data database. data represented $query->result_array() or $query->result() (you're using both of these should use one, once).
so have return $query->result() sends data controller. data stored in $query variable, because have $query = $this->mod_products->cart_product_records($id).
if add !empty() check if statement, this:
if( !empty($query = $this->mod_products->cart_product_records($id)) ){ then, depending on data want $query, you're either going want construct loop (which enable extract multiple ids, prices, etc), or retrieve specific values $query, $query[0][main_products_cat_id] (assuming $query array) or $query[0]->main_products_cat_id (if it's object).
i hope helps!
Comments
Post a Comment