1

I have the below code in of of my models. Im loading the offer details page and it gave me the error

Severity: Notice

Message: Undefined index: viewc

Filename: statistics/Statistic_model.php

Line Number: 551

Statistic_model:

public function getTotalDetailsViewOfActiveOffer($comid) {

    $this->db->select('count(statistic_offer_view_count.id) as viewc');
    $this->db->from('statistic_offer_view_count');
    $this->db->join('offers', 'offers.id = statistic_offer_view_count.offer_id');       
    $this->db->where('offers.com_id',$comid);
    $this->db->where('offers.approved_status',"2"); 
    $this->db->where('offers.enddate >=',date('Y-m-d'));
    $this->db->group_by("offers.com_id");       
    $query = $this->db->get();
    $row = $query->result_array();
    $count=$row['viewc'];           //this is line 551

}

Any idea how to fix this error?

2 Answers 2

2

That error means that the index viewc is not in the array $query->result_array() most likely because your query failed or returned null. You should get into the habit of doing:

$query = $this->db->get();
if ($query->num_rows() > 0) {
    return $query->row()->viewc;
}
return false; // or in this case 0 or whatever
Sign up to request clarification or add additional context in comments.

Comments

1

In Your Code You Selecting data from database Multiple array's.And assigning at to a variable like a single array. Your Code....

$row = $query->result_array();
$count=$row['viewc'];

correct way is in your conduction to assign a variable is....

$data   =   array();
foreah($row as $key => $value){
  $data[$key] = $value['viewc'];
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.