Codeigniter Where 子句不起作用
Codeigniter Where clause not working
Codeigniter Where 子句在使用变量时不起作用。如果我直接为 $price_min 使用数字,这应该可行。
我用的时候
$s=$this->db->where(' prize < ' , $price_max);
这将是 return
prize < [value] => '100' .
而我使用 $s=$this->db->where(' prize < ' , 100);
这将 return
prize < [value] => 100 .
我认为当我使用变量时这个 return 是字符串。如何将其更改为整数?
请关注我的代码
function filter()
{
$state = $this->input->post("state");
$type = $this->input->post('type');
$bed = $this->input->post('bed');
$bath = $this->input->post('bath');
echo $price_min=$this->input->post("price-min"); //output: 5
echo $price_max=$this->input->post("price-max"); //output: 100
$this->db->where(' prize > ' , $price_min);
$s=$this->db->where(' prize < ' , $price_max);
print_r($s);
$filterquery = $this->db->get('details');
$records= $filterquery->result();
return array(
'records' => $records,
'count' => count($records),
);
}
希望这对你有用:
function filter()
{
$state = $this->input->post("state");
$type = $this->input->post('type');
$bed = $this->input->post('bed');
$bath = $this->input->post('bath');
$price_min = $this->input->post("price-min");
$price_max = $this->input->post("price-max");
/*you can set 0 or whatever if post is empty i set null */
$price_min = ! empty($price_min) ? intval($price_min) : NULL;
$price_max = ! empty($price_max) ? intval($price_max) : NULL;
/* you can also check with if statement
if ($price_min != '' && $price_max != '') {
$price_max = intval($price_max);
$price_min = intval($price_min);
your where statement.....
}
*/
$this->db->where('prize >' , $price_min);
$this->db->where('prize <' , $price_max);
$filterquery = $this->db->get('details');
$records = $filterquery->result();
return array(
'records' => $records,
'count' => count($records),
);
}
Codeigniter Where 子句在使用变量时不起作用。如果我直接为 $price_min 使用数字,这应该可行。
我用的时候
$s=$this->db->where(' prize < ' , $price_max);
这将是 return
prize < [value] => '100' .
而我使用 $s=$this->db->where(' prize < ' , 100);
这将 return
prize < [value] => 100 .
我认为当我使用变量时这个 return 是字符串。如何将其更改为整数?
请关注我的代码
function filter()
{
$state = $this->input->post("state");
$type = $this->input->post('type');
$bed = $this->input->post('bed');
$bath = $this->input->post('bath');
echo $price_min=$this->input->post("price-min"); //output: 5
echo $price_max=$this->input->post("price-max"); //output: 100
$this->db->where(' prize > ' , $price_min);
$s=$this->db->where(' prize < ' , $price_max);
print_r($s);
$filterquery = $this->db->get('details');
$records= $filterquery->result();
return array(
'records' => $records,
'count' => count($records),
);
}
希望这对你有用:
function filter()
{
$state = $this->input->post("state");
$type = $this->input->post('type');
$bed = $this->input->post('bed');
$bath = $this->input->post('bath');
$price_min = $this->input->post("price-min");
$price_max = $this->input->post("price-max");
/*you can set 0 or whatever if post is empty i set null */
$price_min = ! empty($price_min) ? intval($price_min) : NULL;
$price_max = ! empty($price_max) ? intval($price_max) : NULL;
/* you can also check with if statement
if ($price_min != '' && $price_max != '') {
$price_max = intval($price_max);
$price_min = intval($price_min);
your where statement.....
}
*/
$this->db->where('prize >' , $price_min);
$this->db->where('prize <' , $price_max);
$filterquery = $this->db->get('details');
$records = $filterquery->result();
return array(
'records' => $records,
'count' => count($records),
);
}