gpt4 book ai didi

PHP 分页查询不起作用

转载 作者:行者123 更新时间:2023-11-29 00:25:41 25 4
gpt4 key购买 nike

在我的 Controller 中,我有以下代码:

if($action=='shipping_list'){ 
$numrows=inquire_row(); //Get number of rows in query
$pages= new Paginator('10', 'p'); //create object
$pages->set_total($numrows);
$shipping=shipping_list(); //Goes to model
include('shipping_list.php');
}

在我的模型中,我使用这些代码:

function shipping_list(){
global $MEMS;
global $pages;
$query = "SELECT * FROM Inventory" .$pages->get_limit()
."WHERE Yield >=320 AND (Q = 'Pass' OR Q='No Q') AND shipdate = ' '
ORDER BY Wafer ASC, RC ASC";
echo $query;
$shipping = $MEMS -> query($query);
var_dump($shipping);
return $shipping;
}

当我回显 $query 时,我得到了

SELECT * FROM Inventory LIMIT 0, 20 WHERE Yield >=320 AND (Q = 'Pass' OR Q='No Q') AND shipdate = ' ' ORDER BY Wafer ASC, RC ASC

所以我知道到那时为止一切都是正确的。但是,当我 var_dump $shipping 时,我得到 bool(false)。为什么我的查询没有返回正确的结果?

最佳答案

您的查询在错误的位置添加了 LIMIT 标签。

LIMIT 标签应该放在最后。

因此,您的查询应该是:

SELECT * FROM Inventory WHERE Yield >=320 AND (Q = 'Pass' OR Q='No Q') AND shipdate = ' ' 按 Wafer ASC, RC ASC LIMIT 0, 20 订购

将模型中的 SQL 修改为:

function shipping_list(){
global $MEMS;
global $pages;
$query = "SELECT * FROM Inventory
WHERE Yield >=320 AND (Q = 'Pass' OR Q='No Q') AND shipdate = ' '
ORDER BY Wafer ASC, RC ASC " .$pages->get_limit(); // ADD LIMIT tag at the end.
echo $query;
$shipping = $MEMS -> query($query);
var_dump($shipping);
return $shipping;
}

关于PHP 分页查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19043504/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com