您好我正在尝试在PHP中找到SQL字段的总和。这个数额必须是 小于或等于我在控制器中收到的数字 JavaScript的。但我的SQL语法不适用于PHP,而是它 从数据库中提取所有行。
public function feedbackaverageAction(){
$value =$_GET['value'];
$db = Zend_Registry::get('dbadapter');
$select = new Zend_Db_Select($db);
$select = $db->select();
$select->from(array('feedback' => 'feedback'),
array ('customdata',
'checkinprocess',
'service_by_owner',
'locationrating',
'cleanlinessrating',
'valueformoneyrating',
'kitchenequipmentrating'));
$select->where('feedback.checkinprocess' +
'feedback.service_by_owner' +
'feedback.locationrating' +
'feedback.cleanlinessrating' +
'feedback.valueformoneyrating' +
'feedback.kitchenequipmentrating' <= $value);
$stmt = $select->query();
$result = $stmt->fetchAll();
$this->view->rows = $result;
}
任何人都可以帮我找到总和并检查它在控制器中得到的值。
答案 0 :(得分:0)
尝试使用此代码并进行SQL查询。
$value = $_GET['value'];
$db = Zend_Registry::get('dbadapter');
$select = new Zend_Db_Select($db);
$select = $db->select();
$select->from(array('feedback' => 'feedback'),array ('customdata','checkinprocess','service_by_owner','locationrating','cleanlinessrating','valueformoneyrating','kitchenequipmentrating'));
$select->where(new Zend_Db_Expr('feedback.checkinprocess'+'feedback.service_by_owner'+'feedback.locationrating'+'feedback.cleanlinessrating'+'feedback.valueformoneyrating'+'feedback.kitchenequipmentrating')<= $value);
$stmt = $select->query();
$result = $stmt->fetchAll();
$this->view->rows = $result;