Anonymous
Как реализовать логику И и ИЛИ с несколькими условными вызовамиwhere_in() в CodeIgniter
Сообщение
Anonymous » 13 янв 2026, 02:57
Как я могу добиться такого результата поиска:
категория (CAT) — это основной запрос; при наличии категории (CAT) результат будет отображаться только в категориях (CAT) с разными местоположениями (INTL, DOM) (текущий код этого не делает).
то же самое с зарплатой (SAL)
Код: Выделить всё
public function seeker($limit='', $start='')
{
if($this->input->get('DOM', FALSE)){
$ukcountry = $this->input->get('DOM', TRUE);
$expukcountry = explode(',', $ukcountry);
if($this->input->get('INTL', FALSE)){
$this->db->or_where_in('m_region.regionID', $expukcountry);
}
else $this->db->where_in('m_region.regionID', $expukcountry);
}
if($this->input->get('INTL', FALSE)){
$intlcountry = $this->input->get('INTL', TRUE);
$expintlcountry = explode(',', $intlcountry);
if($this->input->get('DOM', FALSE)){
$this->db->or_where_in('m_country.code', $expintlcountry);
}
else $this->db->where_in('m_country.code', $expintlcountry);
}
if($this->input->get('SAL', FALSE)){
$salary = $this->input->get('SAL', TRUE);
$expsalary = explode(',', $salary);
$this->db->where_in('job_salary.code', $expsalary);
}
if($this->input->get('CAT', FALSE)){
$category = $this->input->get('CAT', TRUE);
$expcategory = explode(',', $category);
if($this->input->get('INTL', FALSE) && $this->input->get('DOM', FALSE)){
$this->db->where_in('job_category_group.categoryID', $expcategory);
}
else $this->db->or_where_in('job_category_group.categoryID', $expcategory);
}
if($this->input->get()){
$this->db->join('job_category_group', 'emp_jobs.id = job_category_group.postID', 'left');
$this->db->join('job_category', 'job_category_group.categoryID = job_category.code', 'left');
$this->db->join('emp_account', 'emp_jobs.employer_id = emp_account.id', 'left');
$this->db->join('m_region', 'emp_jobs.region_id = m_region.id', 'left');
$this->db->join('m_country', 'emp_jobs.location_id = m_country.id', 'left');
$this->db->join('job_salary', 'emp_jobs.salary_id = job_salary.id', 'left');
$this->db->select('job_category.category');
$this->db->select('job_category_group.postID, job_category_group.categoryID');
$this->db->select('emp_account.company as employerName');
$this->db->select('m_region.name as regionName');
$this->db->select('m_country.name as countryName');
$this->db->select('job_salary.range as salary');
$this->db->select('emp_jobs.title as jobposition');
$this->db->select('emp_jobs.start_date as postdate');
$this->db->where('emp_jobs.status', 'active');
$this->db->limit($limit, $start);
$this->db->group_by('emp_jobs.id');
$this->db->order_by('emp_jobs.start_date', 'desc');
$query = $this->db->get('emp_jobs');
return $query->result_array();
}
}
Подробнее здесь:
https://stackoverflow.com/questions/307 ... calls-in-c
1768262274
Anonymous
[b]Как я могу добиться такого результата поиска:[/b] [list] [*]категория (CAT) — это основной запрос; при наличии категории (CAT) результат будет отображаться только в категориях (CAT) с разными местоположениями (INTL, DOM) (текущий код этого не делает). [*]то же самое с зарплатой (SAL) [code]public function seeker($limit='', $start='') { if($this->input->get('DOM', FALSE)){ $ukcountry = $this->input->get('DOM', TRUE); $expukcountry = explode(',', $ukcountry); if($this->input->get('INTL', FALSE)){ $this->db->or_where_in('m_region.regionID', $expukcountry); } else $this->db->where_in('m_region.regionID', $expukcountry); } if($this->input->get('INTL', FALSE)){ $intlcountry = $this->input->get('INTL', TRUE); $expintlcountry = explode(',', $intlcountry); if($this->input->get('DOM', FALSE)){ $this->db->or_where_in('m_country.code', $expintlcountry); } else $this->db->where_in('m_country.code', $expintlcountry); } if($this->input->get('SAL', FALSE)){ $salary = $this->input->get('SAL', TRUE); $expsalary = explode(',', $salary); $this->db->where_in('job_salary.code', $expsalary); } if($this->input->get('CAT', FALSE)){ $category = $this->input->get('CAT', TRUE); $expcategory = explode(',', $category); if($this->input->get('INTL', FALSE) && $this->input->get('DOM', FALSE)){ $this->db->where_in('job_category_group.categoryID', $expcategory); } else $this->db->or_where_in('job_category_group.categoryID', $expcategory); } if($this->input->get()){ $this->db->join('job_category_group', 'emp_jobs.id = job_category_group.postID', 'left'); $this->db->join('job_category', 'job_category_group.categoryID = job_category.code', 'left'); $this->db->join('emp_account', 'emp_jobs.employer_id = emp_account.id', 'left'); $this->db->join('m_region', 'emp_jobs.region_id = m_region.id', 'left'); $this->db->join('m_country', 'emp_jobs.location_id = m_country.id', 'left'); $this->db->join('job_salary', 'emp_jobs.salary_id = job_salary.id', 'left'); $this->db->select('job_category.category'); $this->db->select('job_category_group.postID, job_category_group.categoryID'); $this->db->select('emp_account.company as employerName'); $this->db->select('m_region.name as regionName'); $this->db->select('m_country.name as countryName'); $this->db->select('job_salary.range as salary'); $this->db->select('emp_jobs.title as jobposition'); $this->db->select('emp_jobs.start_date as postdate'); $this->db->where('emp_jobs.status', 'active'); $this->db->limit($limit, $start); $this->db->group_by('emp_jobs.id'); $this->db->order_by('emp_jobs.start_date', 'desc'); $query = $this->db->get('emp_jobs'); return $query->result_array(); } } [/code] [/list] Подробнее здесь: [url]https://stackoverflow.com/questions/30705032/how-to-implement-and-and-or-logic-with-several-conditional-where-in-calls-in-c[/url]