I see your request with count and where . This means that you simply select one row of data like this.
username COUNT(product_id) admin 3
The returned data is just 1 row, so you can return the data with row() , like this return $query->row() .
Model : return your default data as row() for 1 row of data.
public function c_count($sess) { $query = $this->db->query("SELECT COUNT(product_id) as count_id FROM cart WHERE username = '$sess'"); return $query->row(); }
Controller Call up your data here.
function cart_count() { $sess = $this->session->userdata('SESS_USER'); $query = $this->product_model->c_count($sess); $data['count'] = $query->count_id; // CHANGE FROM $data['count'] = $query->result(); // If you dont mind, I change your code : // $query = $this->db->get("cart"); // $data['records'] = $query->result(); $record = $this->db->get("cart"); $data['records'] = $record->result(); $this->load->view('frontend/menu',$data); }
Views Here's how to name your data, for example, use <span> .
<span>Admin total product : <?php echo $count; ?> Products</span>
There are so many ways to call returned data from a database.
You can also use <?php echo $query->count_id; ?> <?php echo $query->count_id; ?> in their views without setting it to $data['count'] in their controller. You can try it now. :) Hope this help.
Note. If you want to call more than 1 data, do not use where , but use group by . I want to give you an example for this, but this is another problem with your question. :) and if there are any typos, please let me know and I will fix it.
source share