0

I am having a button on a site for "next page" which links to the next page with an item that is older then the one displayed. Then there is a counter (4/10), showing the position.

This dataset will fail on my approach:

date_created
2018-11-27 22:31:11
2018-11-27 22:31:11
2018-11-27 22:31:12
2018-11-27 22:31:12
2018-11-27 22:31:12
2018-11-27 22:31:12
2018-11-27 22:31:13
2018-11-27 22:31:14

Getting next URL works as I am also using ID:

SELECT URL
FROM items
ORDER BY ca.date_created ASC, ca.ID ASC LIMIT 1

The item position failes and is calculated like this:

SELECT count(ID) AS c 
FROM table  
WHERE date_created > '2018-11-27 22:31:10'

How could I alter the logic or the SQL to show the correct position from the current item on? I am using MySQL.

SELECT count(ID) AS c 
FROM table  
WHERE date_created > '2018-11-27 22:31:10'
merlin
  • 2,717
  • 3
  • 29
  • 59
  • I think what you are looking after is Pagination. For eg: https://stackoverflow.com/questions/3705318/simple-php-pagination-script Google "Pagination" and you will get more relevant results as well – Madhur Bhaiya Nov 28 '18 at 17:25
  • To select before and after of selected row see the example in my question here: https://stackoverflow.com/q/40024573/5617911 – ICE Nov 29 '18 at 23:54

0 Answers0