如何在codeigniter中使用BETWEEN条件?[副本]

41zrol4v  于 8个月前  发布在  其他
关注(0)|答案(3)|浏览(80)

此问题已在此处有答案

using BETWEEN in WHERE condition(7个回答)
上个月关门了。
验证码:

$salarymin = 200000;
$salarymax = 500000;
$title = java;

$this->db->select('*');
$this->db->from('job');
$where = "((salary_range_min='".$salarymin."') and (salary_range_max='".$salarymax."')) and (job_title like '".$title."%' or skill like '%".$title."%')";
$this->db->where($where);
$query = $this->db->get();
$result = $query->result_array();
return $result;

在我的表job中,我定义了salary_range_min and salary_range_max
如何获取工资在200000 and 500000之间的数据?

4smxwvx5

4smxwvx51#

请使用这个:

$this->db->where('salary >', 200000);
$this->db->where('salary <', 500000);
$result = $this->db->get('job')->result_array();

注:“salary”是列名。如果它是不同的,只是改变它。

oiopk7p5

oiopk7p52#

$this->db->where('salary_range_min >= ',$salarymin)
$this->db->where('salary_range_max <= ',$salarymax)
$this->db->where('job_title like '.$title.'% or skill like %'.$title.'%');
// OR */
$this->db->where('job_title like '.$title.'% or skill like %'.$title.'%',FALSE);
// OR */
$this->db->where('job_title like '.$title.'% or skill like %'.$title.'%',NULL);

可以多次调用where方法。你想怎么说都行如果你想在你的hole语句后面读取生成的查询,写:

$this->db->last_query();

为了更好地理解你的陈述

a5g8bdjr

a5g8bdjr3#

$where = "((salary_range_min <= '".$salarymin."') and (salary_range_max >= '".$salarymax."'))";
$like = "(job_title like '".$title."%' or skill like '%".$title."%')";
$this->db->like($like);
$this->db->where($where, null, false);

相关问题