2

I asked a question yesterday titled "How do i use binded variables with MySql LIMIT clause. Sorry, I guess it was not clear enough and got 30 views but no suggestions. So here is what I found after a day of trial and error. First, I discovered that the the LIMIT is the actual physical position of a record in a table not my auto_incremented id_ number. A lot of documentation i read also indicated it was the OFFSET that held the record position, so I wasted a lot of time with weird results. Second, I found documentation with a couple of ways to bind a variable to LIMIT. None of them worked, so I resorted to assigning a $variable to the LIMIT as follows.

("SELECT * FROM $livetable WHERE cust_zip = :cust_zip
HAVING distance < :mydistance ORDER BY client_id ASC LIMIT $start_record_position 
, $how_many_records_to_display");

This works for me but any better suggestions, would be appreciated. And I hope this will save someone else a day of figuring this out.

Ricky T
  • 243
  • 1
  • 13
  • Are you asking how LIMIT and OFFSET work with MySQL or is there a specific problem you're having with using them through PDO? Limit is the number of items, offset is where to start. – Matt Mar 29 '17 at 17:37
  • Thats what all the docs say that I have read to. But I is working backwards for me, where LIMIT $_where_to_start, $_number_of_items. And if I use the word OFFSET in my code I get a error, so I have to use the format of LIMIT a , b – Ricky T Mar 29 '17 at 17:45
  • The above was only my first step, still needs page control for next and previous. I think this stack overflow article will answer all my questions http://stackoverflow.com/questions/20364349/pagination-using-mysql-limit-offset – Ricky T Mar 29 '17 at 18:20
  • http://stackoverflow.com/questions/20364349/pagination-using-mysql-limit-offset – Ricky T Mar 29 '17 at 18:24

0 Answers0