3

I created a pagination by roughly following this link:

http://www.awcore.com/dev/1/3/Create-Awesome-PHPMYSQL-Pagination_en#toggle

quite cool. Although I have an issue with my query.

It works fine like this:

require 'includes/function.php';

    $page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
    $limit = 8;
    $startpoint = ($page * $limit) - $limit;

    $statement = "cars WHERE deleted = 'no'";

$query = mysql_query("SELECT * FROM {$statement} LIMIT {$startpoint}, {$limit} ");

while ($row = mysql_fetch_assoc($query)) {

However when I try to add an ORDER BY to this, like so:

require 'includes/function.php';

    $page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
    $limit = 8;
    $startpoint = ($page * $limit) - $limit;

    $statement = "cars WHERE deleted = 'no'";

$query = mysql_query("SELECT * FROM {$statement} LIMIT {$startpoint}, {$limit} ORDER BY model DESC");

while ($row = mysql_fetch_assoc($query)) {

or just change the statement like this:

$statement = "rcr_cars WHERE deleted = 'no' ORDER BY model DESC";

I get this error:

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in filepath/myfile.php on line 79.

Line 79 is this line:

 while ($row = mysql_fetch_assoc($query)) {

Can anyone tell me how I am not using the ORDER BY correctly, its got me puzzled. :/

2

3 Answers 3

3

Try the query as below

$query = mysql_query("SELECT * FROM {$statement} ORDER BY model DESC LIMIT {$startpoint}, {$limit} ");

Where you have gone wrong is LIMIT should come after ORDER BY. Read more

Sign up to request clarification or add additional context in comments.

Comments

0

Change the query:

$query = mysql_query("SELECT * FROM {$statement} ORDER BY model DESC LIMIT {$startpoint}, {$limit}") ;

Comments

0
$query = mysql_query("SELECT * FROM {$statement} ORDER BY model DESC LIMIT {$startpoint}, {$limit} ");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.