1

In my controller I have the following code:

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');
}

In my model I these codes:

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;
}

When I echo $query, I get

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

So I know everything is right up to that point. However, when I var_dump $shipping, I get bool(false). Why isn't my query returning the right results?

1
  • Wrong query LIMIT should come at the end... Commented Sep 27, 2013 at 5:53

3 Answers 3

1

Your Query is adding LIMIT tag at wrong place.

LIMIT tag should go at the end.

So, your query should be:

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

Modify the SQL from model as :

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;
}
Sign up to request clarification or add additional context in comments.

1 Comment

@user2773365, if this is solution to your question, please consider it marking as solution.
0

LIMIT should be at the end of the query

 $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();

Comments

0

Pagination query looks like

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

You will have to specify $start and $limit

Let's suppose 20 results on first page.

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

in your case it will change to something like that

$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();

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.