【发布时间】:2014-09-29 02:29:05
【问题描述】:
当我运行这个时,我遇到了这个问题。
$results = mysqli_query($connecDB,"SELECT COUNT(*) FROM customers
RIGHT JOIN orders on customers.serial=orders.serial
RIGHT JOIN order_detail on orders.serial=order_detail.orderid
LEFT JOIN inventory on order_detail.productid=inventory.prod_id");
$get_total_rows = mysqli_fetch_array($results); //total records
即使它是空白的,它也会显示其他页面。我已经尝试过其他不需要我加入的表,并且它适用于它们。但是有了这个,它就不能完美地工作了。
如何修复我的计数功能?
这是我在调整分页代码之前的原始查询。
SELECT DISTINCT customers.order_status,customers.serial,customers.name,customers.address,customers.phone,customers.email,customers.payment,customers.carrier,customers.tracking_no, orders.date, order_detail.productid, order_detail.quantity, order_detail.price, inventory.prod_name
FROM customers
RIGHT JOIN orders on customers.serial=orders.serial
RIGHT JOIN order_detail on orders.serial=order_detail.orderid
LEFT JOIN inventory on order_detail.productid=inventory.prod_id
GROUP BY orders.date, order_detail.orderid
ORDER BY order_detail.orderid DESC";
【问题讨论】:
-
我对你的问题完全糊涂了。您的第一个查询有
count(*)而没有group by,所以它总是返回一行。因此,没有“附加行”。第二个有一个group by,所以它似乎与第一个无关。另外,你有这种奇怪的外连接混合,这使得查询很难解开。 -
我的第一个查询是针对单个表的,我从互联网上下载了一个演示,我对其进行了调整,但在连接表时遇到了问题,因此我的第二个查询。 @GordonLinoff
-
我想知道你是否从查询中得到了想要的结果。不推荐使用右连接,所以同时使用左连接和右连接只会导致混乱
-
@Gervs 我的查询工作正常。呵呵。
标签: mysql sql pagination