0

I made a Randompicker where 10 users are selected randomly and added to a database table called "winners". Every time I click on my button 10 winners are getting selected and added to the table. I'm able to get the last 10 winners with a simple sql query.

SELECT * from winners order by id desc limit 10;

I use Ajax and print out the 10 rows as a table. The next step would be adding a "Previous" and "Next" button. If I click on the "Previous" Button I need to get the "second latest" 10 winners. What kind of a query would be needed? The button will be clickable until the oldest 10 winners are getting shown.

The winners table structure looks like this:

NR USERID USERNAME DATE

I can't figure out how to do that.

Preprocezzor
  • 197
  • 1
  • 5
  • 17
  • 1
    It is a pagination problem. With every Next/Previous button, you specify a page number and limit to get next records using LIMIT – Madhur Bhaiya Aug 26 '18 at 16:54
  • Got it. I just needed the specific name of the problem. Now I will be able to read about it! – Preprocezzor Aug 26 '18 at 16:55
  • MySQL SELECT supports an OFFSET in the LIMIT clause. See https://dev.mysql.com/doc/refman/8.0/en/select.html. – steffen Aug 26 '18 at 16:57

0 Answers0