Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 在Cakephp中从数据库中选择数据不起作用_Mysql_Sql_Cakephp - Fatal编程技术网

Mysql 在Cakephp中从数据库中选择数据不起作用

Mysql 在Cakephp中从数据库中选择数据不起作用,mysql,sql,cakephp,Mysql,Sql,Cakephp,我想选择类似以下SQL查询的数据: SELECT discounts.product_id, products.product_name, sum(products.product_price - discounts.product_discount) as total_Amount, count(orders.order_id) as total_Number FROM products inner join discounts on products.product_id = discou

我想选择类似以下SQL查询的数据:

SELECT discounts.product_id, products.product_name,
sum(products.product_price - discounts.product_discount) as total_Amount,
count(orders.order_id) as total_Number
FROM products 
inner join discounts on products.product_id = discounts.product_id
inner join orders on discounts.discount_id = orders.discount_id

where discounts.start_time >= @from and discounts.end_time <= @to 

group by discounts.product_id,products.product_name
@from和@to是我将传递给的值

以下是我在控制器中所做的:

$from='27 November 2012';
        //$this->layout = 'customer-backend';
        $this->Order->recursive=-1;
        $this->Order->virtualFields['benefit']='SUM(Product.product_price - Discount.product_discount)';
        $this->Order->virtualFields['number']='COUNT(Order.order_id)';
        $option['joins'] = array(
            array('table'=>'discounts',
                'alias'=>'Discount',
                'type'=>'INNER',
                'conditions'=>array(
                    'Order.discount_id = Discount.discount_id',
                )
            ),
            array('table'=>'products',
                'alias'=>'Product',
                'type'=>'INNER',
                'conditions'=>array(
                    'Discount.product_id = Product.product_id'
                )
            )
        );
        $option['fields']= array('Discount.product_id','Product.product_name','benefit','number');
        $option['conditions']=array('Discount.start_time >='=>$from, 'Discount.end_time <= ' => $to);   //I guess it's wrong here
        $option['group'] = array('Discount.product_id','Product.product_name');
        //$option['limit']=20;
        $products = $this->Order->find('all',$option);
        $this->set('products',$products);
我认为这句话是错误的:

$option['conditions']=array('Discount.start_time >='=>$from, 'Discount.end_time <= ' => $to);
当我删除它时,它起作用了。但我不知道如何修复它。
请帮帮我。

这不是CakePHP的问题,但它们是MYSQL接收您的查询的方式。尝试格式化日期

$from = date('Y-m-d', strtotime($from));

在这一点上也一样——如果你打算使用MySQL,学习如何调试它。CakePHP正在生成什么查询?如果你能证明这一点,这将很容易解决。@Dave我是Cakephp新手。你能告诉我如何调试它吗?我不能,但我的好朋友谷歌很乐意帮忙。他有很多朋友都曾多次问过同样的问题;不是想成为一个混蛋-只是。。。这是一个非常常见的问题,这里不是回答这个问题的地方。谢谢你的回答。日期格式为“dd月yyyy”。例如2013年11月8日。当我直接在mySQL中输入它时,它工作了。列类型是什么?约会时间?日期