on-internet
← Community

My CodeIgniter query containing a mix of AND and OR conditions in the WHERE clause doesn't return the right count [duplicate]

Stack Overflow ·

I really can't see where the issue is here. EX: A BMW is on sale in New York (city_id = 5) and Connecticut (city_id = 3), so when user enters BMW in search box it returns 2 results where it should only be 1. public function search_result_count($search) { $count=0; $search = addslashes($search); $city_id = $this->tank_auth->get_user_city()->id; $sql="select count(id) as count from ".$this->table_name." where title LIKE '%$search%' or zipcode like '%$search%' and city_id ='$city_id' "; $query=$this->db->query($sql); if($row=$query->row()) { $count=$row->count; } return $count; } Even if I assign

Comments

Sign in or sign up to comment and upvote.

No comments yet.