SQL WHERE不适用于CakePHP 2

时间:2016-08-18 11:09:16

标签: php sql cakephp

这是我之前提出的问题,但问题发生了变化,所以我问了一个新问题。

我有一个名为销售的表和3行名为卖方买方价格

在HTML页面中,我在myview.ctp的HTML表格中显示此查询的结果:

public function myview() {
    $this->set('mysales', $this-Sales>find('all', 
    array('sum(price)AS total','group' => array('seller_name','buyer_name'))));
}

在显示结果的每一行中,都有一个链接,用于发送卖家名称和所点击行的买家名称,并有助于创建包含销售详情的PDF:

<?php echo $this->Html->link("PDF", array(
    "controller" => "name of controller",
    "action"     => "myview_pdf",
    "?" => array(
       "seller_name0" => $thesales['Sales']['seller_name'],
       "buyer_name0" => $thesales['Sales']['buyer_name']
    )
 )); ?>

我在控制器中获得了此功能,该控制器接收所点击行的卖家和买家名称:

public function myview_pdf(){

    $this->set('seller_name1', $this->request->query("seller_name0"));
    $this->set('buyer_name1', $this->request->query("buyer_name0")); 
}

现在我想做这个SQL查询:

SELECT detail1_of_sale, detail2_of_sale, detail3_of_sale, detail4_of_sale
FROM sales
WHERE seller_name = 'seller_name1', buyer_name = 'buyer_name1'

我希望能帮助我显示涉及seller_name1和buyer_name1

的销售详情

我试图做的是(在控制器中,函数myview_pdf):

$this->set('mysales', $this->Sales->find('all',
            array(
                'fields' => array('detail1_of_sale','detail2_of_sale','detail3_of_sale','detail4_of_sale'),
                'conditions' => array('seller_name' => $seller_name1, 'buyer_name' => $buyer_name1)
            )
        ));

我不知道这是一个语法错误还是只是告诉我$ seller_name1和$ buyer_name1是未定义的变量。

注意:当我取消条件时,$ seller_name1和$ buyer_name1会以简单的回显正确显示。

非常感谢Object Manipulator帮助我到目前为止

0 个答案:

没有答案