Pagination -> mysql limit not working correctly

Hello,
I’m working with a pagination script i found on http://www.daveismyname.com/tutorials/php-tutorials/pagination-with-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?

Kind of a guess but it looks like yu need a space after the table name. So try:



$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.