根据ZF.i有任何人更正此查询的情况用户选择不同的参数,并在此基础上进行查询
$user = new Zend_Session_Namespace('user');
$phone_service_id = $user->phone_service_id;
$start_date = $this->_getParam('start_date'); //02/07/2012
$end_date = $this->_getParam('end_date'); //02/21/2012
$option_call_log = $this->_getParam('option_call_log'); //COLUMN NAME
$option_call_log_asc_desc = $this->_getParam('option_call_log_asc_desc'); //ASC/DESC
我认为我在查询中有语法错误,请在此处查看
$select = $DB->select()
->from('CALL_LOG', array('caller_name','call_number','call_start_time','call_duration','call_direction'))
->where('phone_service_id = ?', $phone_service_id)
->where(DATE_FORMAT(date_created, '%m/%d/%Y') BETWEEN $start_date AND $end_date)
->order($option_call_log $option_call_log_asc_desc)
->limit(0,9);
这有什么不对吗?
答案 0 :(得分:2)
BETWEEN子句是包含在内的,正确的方法如下所示:
$select = $DB->select()
->from('CALL_LOG', array('caller_name','call_number','call_start_time','call_duration','call_direction'))
->where('phone_service_id = ?', $phone_service_id)
->where("DATE_FORMAT(date_created, '%m/%d/%Y') >= ?", $start_date)
->where("DATE_FORMAT(date_created, '%m/%d/%Y') <= ?", $end_date)
->order("".$option_call_log." ".$option_call_log_asc_desc)
->limit(0,9);
尝试上面的代码,你的问题就会解决。
答案 1 :(得分:0)
zend db也用于magento所以我找到了方法。
$sql = $read->select()
->from(array('g' => $res->getTableName('geoloc')));
$whereSql = "INET_ATON('{$remoteAddr}') BETWEEN g.start AND g.end";
$sql = $sql->where($whereSql); //echo $sql;exit;
$result = $read->fetchRow($sql);
输出如下:
希望它有所帮助。SELECT
g
。* FROMgeoloc
ASg
WHERE (INET_ATON('41 .98.30.186')BETWEEN g.start AND g.end)