Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7442113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:07:36+00:00 2026-05-29T11:07:36+00:00

I am receiving a pagination error in my php script. The query works fine

  • 0

I am receiving a pagination error in my php script. The query works fine when being ran directly inside mysql workbench and comes back with the proper results.

Error Returned: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘LIMIT 0, 20’ at line 2

    $getpositive = "select case_number, c.name as subject, a.name, u.first_name, u.last_name from cases as c join cases_cstm as cc on c.id = cc.id_c
                left join accounts as a on a.id = c.account_id left join users as u on u.id = c.assigned_user_id where rating_c ='1';";
$db -> PS_Pagination($getpositive, 20, 5, "");
$db -> setDebug(true);
$rs = $db->paginate();
$positive_rating_rows = mysql_num_rows($rs);

I am then displaying those results in a table:

while($val = mysql_fetch_assoc($rs)) 
        {          

        ?>
                </tr>
                <tr>
                    <td width="7%"><?=$val['case_number']?></td>
                    <td width="40%"><?=$val['subject']?></td>
                    <td width="40%"><?=$val['name']?></td>
                </tr>

Here is my pagination function:

public function PS_Pagination($sql, $rows_per_page = 10, $links_per_page = 5, $append = "") {
    //$this->conn = $connection;
    $this->sql = $sql;
    $this->rows_per_page = (int)$rows_per_page;
    if (intval($links_per_page ) > 0) {
        $this->links_per_page = (int)$links_per_page;
    } else {
        $this->links_per_page = 5;
    }
    $this->append = $append;
    $this->php_self = htmlspecialchars($_SERVER['PHP_SELF'] );
    if (isset($_GET['page'] )) {
        $this->page = intval($_GET['page'] );
    }
}

public function paginate() {
    //Check for valid mysql connection
    if (! $this->IsConnected()) {
        $this->SetError("No connection");
        return false;
    }

    //Find total number of rows
    $all_rs = @mysql_query($this->sql );
    if (! $all_rs) {
        if ($this->debug)
            echo "SQL query failed. Check your query.<br /><br />Error Returned: " . mysql_error();
        return false;
    }
    $this->total_rows = mysql_num_rows($all_rs );
    @mysql_close($all_rs );

    //Return FALSE if no rows found
    if ($this->total_rows == 0) {
        if ($this->debug)
            //echo "Query returned zero rows.";
        return FALSE;
    }

    //Max number of pages
    $this->max_pages = ceil($this->total_rows / $this->rows_per_page );
    if ($this->links_per_page > $this->max_pages) {
        $this->links_per_page = $this->max_pages;
    }

    //Check the page value just in case someone is trying to input an aribitrary value
    if ($this->page > $this->max_pages || $this->page <= 0) {
        $this->page = 1;
    }

    //Calculate Offset
    $this->offset = $this->rows_per_page * ($this->page - 1);

    //Fetch the required result set
    //echo $this->sql . " LIMIT {$this->offset}, {$this->rows_per_page}";
    $rs = @mysql_query($this->sql . " LIMIT {$this->offset}, {$this->rows_per_page}" );
    if (! $rs) {
        if ($this->debug)
            echo "Pagination query failed. Check your query.<br /><br />Error Returned: " . mysql_error();
        return false;
    }
    return $rs;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:07:37+00:00Added an answer on May 29, 2026 at 11:07 am

    You have a ; at the end of your query, and you’re then trying to add LIMIT 0,20 to the end. So it looks like this: blah blah blah where something=value; LIMIT 0,20. This won’t work. Remove the ; to fix.

    Side note, you may be interested in the SQL_CALC_FOUND_ROWS syntax, as this will greatly optimise your pagination method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

receiving error: PHP Notice: Undefined index: mode in /web/ee_web/include/form-modal.php on line 51 line 51
I'm receiving a Resource interpreted as script but transferred with MIME type application/json error
Receiving Error message when performing Update Statement, but database is being updated. Error: You
I'm receiving Package Load Failure error when I open VS 2005 after I installed
I am currently receiving this error: Validation of viewstate MAC failed. If this application
I'm receiving suddenly this error on a Win2003 Server Web Application: Microsoft VBScript runtime
I have tried several things but I can't get the MySQL query in my
Receiving error: [debug] mod_headers.c(663): headers: ap_headers_output_filter() after I included this within the htaccess file:
Im receiving error C2082: redefinition of formal parameter 'rval' in this code while trying
Im receiving the following error Name 'Encryption' is not declared. On Line If reader_login(password).ToString()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.