0

您好我正在尝试在 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;
}

谁能帮助我如何找到总和并将其检查到我在控制器中获得的值。

4

1 回答 1

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;
于 2012-09-26T12:32:02.250 回答