SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    157
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Pagination -> mysql limit not working correctly

    Hello,
    I'm working with a pagination script i found on http://www.daveismyname.com/tutorial...h-a-php-class/.

    Error message received at initial start :ERROR: SQLSTATE[42000]: Syntax error or access violation: 1064 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 '0,5' at line 1

    I believe the problem is with the way i wrote my sql statement more specifically : $pages->get_limit()
    try
    { $queue2 = $dbcon1 ->query("SELECT tbl_incident.inc_index, tbl_incident.inc_title FROM tbl_incident". $pages->get_limit());
    $results = $queue2->fetchAll(PDO::FETCH_ASSOC);
    } catch(PDOException $e) { echo 'ERROR: ' . $e->getMessage(); }

    According to the website, this is how it should be done.
    $data = $db->query('SELECT * FROM table '.$pages->get_limit());

    - the class works as it shows the page links.
    - as you can see below from the error message i copy/pasted on the sec. link click (page2) the page numbers do change.

    ERROR: SQLSTATE[42000]: Syntax error or access violation: 1064 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 '5,5' at line 1

    how do i fix this?

  2. #2
    SitePoint Guru
    Join Date
    Nov 2003
    Location
    Huntsville AL
    Posts
    698
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)
    Kind of a guess but it looks like yu need a space after the table name. So try:

    PHP Code:

    $queue2 
    $dbcon1 ->query("SELECT tbl_incident.inc_index, tbl_incident.inc_title FROM tbl_incident "$pages->get_limit()); 

  3. #3
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by ahundiak View Post
    Kind of a guess but it looks like yu need a space after the table name. So try:

    PHP Code:

    $queue2 
    $dbcon1 ->query("SELECT tbl_incident.inc_index, tbl_incident.inc_title FROM tbl_incident "$pages->get_limit()); 
    This.

    I like to prep my SQL statement in a variable, and pass that variable to the query function so that I can easily print the statement if I run into any issues, for easier time debugging things such as this.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •