如何删除BETWEEN条件cakephp中的单引号

问题描述 投票:0回答:2

我试图将单引号与cakephp 2中的BETWEEN条件中的值分开,但它总是得到带有单引号的值,如BETWEEN'2'和'34'。这是我的代码:

$ref_no1 = $this->request->data['Lead']['ref_no1'];
$ref_no2 = $this->request->data['Lead']['ref_no2'];

$customerHo = $this-> Customer -> find('all',array(
'order' => array('Customer.customer_name' => 'asc'),
'joins'=>array( 
array('table'=>'leads','alias'=>'Lead','type'=>'LEFT','foreignKey'=>false,'conditions'=>array('Customer.customer_id = Lead.customer_id')),
),
'fields'=>'Customer.*,Lead.*',
'conditions' => array(
'Customer.status' => 'active','Customer.customer_id Like'=>'S%',
'Customer.company_id'=>$company_id,
'AND' => array(
array('Lead.ref_no BETWEEN ? and ?' => array($ref_no1,$ref_no2) ),
),
)));

我得到的输出如下:

SELECT `Customer`.*, `Lead`.*
FROM `customers` AS `Customer`
LEFT JOIN `timezip_db_demo`.`leads` AS `Lead` ON (`Customer`.`customer_id` = `Lead`.`customer_id`)
WHERE  `Customer`.`customer_id` Like 'S%' AND
`Lead`.`ref_no` BETWEEN '2' and '34' 
ORDER BY `Customer`.`customer_name` asc

预期产量:

SELECT `Customer`.*, `Lead`.* 
FROM `customers` AS `Customer`  
LEFT JOIN `timezip_db_demo`.`leads` AS `Lead` ON (`Customer`.`customer_id` = `Lead`.`customer_id`)
WHERE  `Customer`.`customer_id` Like 'S%' AND 
`Lead`.`ref_no` BETWEEN 2 and 34 
ORDER BY `Customer`.`customer_name` asc
cakephp cakephp-2.0
2个回答
0
投票

你不能这样做吗?我还没有测试这段代码。

$ref_no1 = $this->request->data['Lead']['ref_no1'];
$ref_no2 = $this->request->data['Lead']['ref_no2'];

$customerHo = $this-> Customer -> find('all',array(
'order' => array('Customer.customer_name' => 'asc'),
'joins'=>array( 
array('table'=>'leads','alias'=>'Lead','type'=>'LEFT','foreignKey'=>false,'conditions'=>array('Customer.customer_id = Lead.customer_id')),
),
'fields'=>'Customer.*,Lead.*',
'conditions' => array(
'Customer.status' => 'active','Customer.customer_id Like'=>'S%',
'Customer.company_id'=>$company_id,
'AND' => array(
array('Lead.ref_no BETWEEN' . $ref_no1 . 'and' . $ref_no2 ),
),
)));

0
投票

你可以将该字符串转换为整数,我希望它会工作

 array((int)$ref_no1,(int)$ref_no2)
© www.soinside.com 2019 - 2024. All rights reserved.