gpt4 book ai didi

php - 如何在php中动态添加多个WHERE子句

转载 作者:行者123 更新时间:2023-11-29 06:26:58 24 4
gpt4 key购买 nike

<分区>

我有五个输入字段,即技能、位置、公司、经验和薪水。根据用户要求,我将从数据库中获取值。我的问题是,如何动态使用 where 条件?考虑用户在技能和公司输入字段中输入值,我想从数据库中获取这些值该怎么做?现在我保留了 20 个 if 条件来解决这个问题

public function get_jobonline($skillname,$userid,$location)
{
$company=$this->input->post('searchcompany');
$experience=$this->input->post('experience');
$salary=$this->input->post('salary');
echo $company;
if($location==NULL)
{
$query=$this->db->query("SELECT j.id AS job_id, j.created_date,j.title, l.city AS location, cm.name AS company_name,
cm.logo FROM `jobs` AS j
LEFT JOIN `keyword` AS k ON `k`.`job_id` = `j`.`id`
LEFT JOIN `keyword_master` AS km ON `km`.`id` = `k`.`keyword_id`
LEFT JOIN `location_master` AS l ON `l`.`id` = `j`.`location`
LEFT JOIN `company_master` AS cm ON `cm`.`id` = `j`.`company_id`
WHERE km.name = '$skillname' AND j.uid='$userid'
;");
}
else
{
$query=$this->db->query("SELECT j.id AS job_id, j.created_date,j.title, l.city AS location, cm.name AS company_name,
cm.logo FROM `jobs` AS j
LEFT JOIN `keyword` AS k ON `k`.`job_id` = `j`.`id`
LEFT JOIN `keyword_master` AS km ON `km`.`id` = `k`.`keyword_id`
LEFT JOIN `location_master` AS l ON `l`.`id` = `j`.`location`
LEFT JOIN `company_master` AS cm ON `cm`.`id` = `j`.`company_id`
WHERE km.name = '$skillname' AND j.uid='$userid' AND l.city='$location'
;");
}

// if($company != NULL && )

return $query->result_array();
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com