"where"的 php mysql 查询错误

标签 php mysql where-clause

<分区>

我正在查询我们的客户订单数据库以查看上周的销售额。查询如下所示:

select
distinct day(from_unixtime(customerorder.datetime)) as day,
count(distinct customerorder.customerorderid) as count_totalorders,
count(distinct customerorderpos.itemid) as count_differentitems,
sum(customerorderpos.quantity_ordered) as quantity_ordered,
sum(customerorderpos.itemsubtotal) as item_subtotal,
sum(customerorderpos.pricechangetotal) as item_pricechangetotal,
sum(customerorderpos.itemtotal) as item_total,
sum(customerorderpos.purchase_price * customerorderpos.quantity_ordered) as item_purchasepricetotal,
sum(distinct cart_discounttotal) as total_discount,
sum(customerorderpos.itemtotal - (customerorderpos.purchase_price * customerorderpos.quantity_ordered) - (select distinct cart_discounttotal)) as item_earningstotal,
sum(distinct cart_total_shipping) as total_shipping,
sum(distinct cart_total_tax) as total_tax,
sum(distinct cart_total_complete) as total_complete
from customerorder
inner join customerorderpos on customerorder.customerorderid = customerorderpos.customerorderid
where
customerorder.datetime >= 1351494000 and
customerorder.status_cancelled = "0"
group by day(from_unixtime(customerorder.datetime))
order by customerorder.datetime

当我在 PhpMyAdmin 中输入查询时,工作正常并显示最近 7 天的订单。但是当我们在自己的软件中运行它时,它会报错。

$result = $db->query($query);
while ($row = $result->fetch_assoc()){

这表明:“ fatal error :调用非对象上的成员函数 fetch_assoc()”

但是....如果我从查询中取出“where customerorder.datetime >= 1351494000”,它就可以正常工作。 换句话说,查询可以完美运行,直到我想将其限制在特定时间。 Customerorder.datetime 是一个带有时间戳的 int(11) 列。

知道问题出在哪里吗?

感谢您的帮助!

最佳答案

我觉得问题出在这部分

      customerorder.datetime >= 1351494000

像这样:

      customerorder.datetime >= '1351494000'

您必须将其附上才能使其正常工作。希望对您有所帮助。

关于 "where"的 php mysql 查询错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13242955/

相关文章:

php - Ubuntu 12.04 php、mysql-server 和 phpmyadmin 安装 apache2 Web 服务器错误

php - Joomla 如何在提交表单时路由到 Controller 方法?

mysql - 为什么时间戳字段不能获得默认值?

php - 使用 Kohana ORM 查询 IN (2,3,4)

mysql - 是否有类似 "NOT HAVING"的 "WHERE XXX NOT IN"语法?

php - Php是否支持方法重载

php - 如何从单独的脚本轮换 Winston 日志?

mysql - 错误1064#使用mysql Like关键字时

c# - 获取 Mysql 中的 Text 和 int 表单并存储在文本框中

sql - Postgres数组在where子句中查找多个值