Object of class CI_DB_mysqli_result could not be converted to string
$data is an object you cant concatinate string to object.
$query = "SELECT * FROM coursesplace WHERE 1=1" if(isset($course)) $query .= " AND course=\"$course\" "; if(isset($location)) $query .= " AND location=\"$location\" "; if(isset($price)) $query .= " AND price=\"$price\" "; $data = $this->db->query($query);
This will help.i have taken a variable $query and assign string to itaccording to the conditions string is concatenated. And at the end the final query is give to $this->db->query
You can just simply get rid of quotes as
$data = 'SELECT * FROM coursesplace WHERE 1=1';if ($course) $data .= " AND course='$course' ";if ($location) $data .= " AND location='$location' ";if ($price) $data .= " AND 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;}
Your problem is you're running the query, then trying to ammend the query afterwards.
You should add "SELECT * FROM coursesplace WHERE 1=1" to the $data string, like this;
$data = 'SELECT * FROM coursesplace WHERE 1=1';// Then ammend the $dataif($course) $data .= "AND course=\"$course\" ";if($location) $data .= "AND location=\"$location\" ";if($price) $data .= "AND price=\"$price\"";// Now run the query$query = $this->db->query($data);return $query->result_array();