1

在我的控制器中,我有以下代码:

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)。为什么我的查询没有返回正确的结果?

4

3 回答 3

1

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

LIMIT标签应该放在最后。

因此,您的查询应该是:

SELECT * FROM Inventory WHERE Yield >=320 AND (Q = 'Pass' OR Q='No Q') AND shipdate = ' ' ORDER BY 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;
}
于 2013-09-27T05:49:39.977 回答
0

LIMIT 应该在查询的末尾

 $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();
于 2013-09-27T05:51:03.847 回答
0

分页查询看起来像

$sql= "SELECT * FROM $tableName LIMIT $start, $limit";

您必须指定$start$limit

让我们假设第一页上有 20 个结果。

$sql= "SELECT * FROM $tableName LIMIT 0, 20";

在你的情况下,它会变成这样

$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();
于 2013-09-27T06:04:49.397 回答