php - Object of class CI_DB_mysqli_result could not be converted to string -


here code :

class mymodel extends ci_model {  public function getinstitution()     {     $course = "programming";     $location = "jakarta";     $price = "price2";      $data = $this->db->query('select * coursesplace 1=1');      if($course)     $data .= "and course=\"$course\" ";     if($location)   $data .= "and location=\"$location\" ";     if($price)      $data .= "and price=\"$price\"";      return $data->result_array();     } } 

i want filter computer course places based on 3 variables (course, location , price), string data type. have "programming", "jakarta", , "price2" example.

but, have error :

a php error encountered

severity: 4096

message: object of class ci_db_mysqli_result not converted string

filename: models/mymodel.php

line number: 14

---> line 14 :

if($course)     $data .= "and course=\"$course\" "; 

and other error :

a php error encountered

severity: error

message: call member function result_array() on non-object

filename: models/mymodel.php

line number: 18

---> line 18 :

return $data->result_array(); 

what should do? answer !

you can rid of quotes as

$data = 'select * coursesplace 1=1';  if ($course)     $data .= " , course='$course' "; if ($location)     $data .= " , location='$location' "; if ($price)     $data .= " , price='$price'";  $result = $this->db->query($data); return $result->result_array(); 

active records..

public function getinstitution() {     $course = "programming";     $location = "jakarta";     $price = "price2";      $this->db->select('*');     $this->db->from('coursesplace');     $this->db->where('1 = 1');     if ($course != '') {         $this->db->where('course', $course);     }     if ($location != '') {         $this->db->where('location', $location);     }     if ($price != '') {         $this->db->where('price', $price);     }     $data = $this->db->get()->result_array();     return $data; } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -