Let me explain what I am trying to do. First, here is a preview of my results so far:

My Query:
SELECT slides.name as slide, filename, time, sort_id
FROM `slide_sort`
INNER JOIN slides
ON slide_sort.slide_id = slides.id
WHERE slide_sort.user_id = 1
So each slide is a page that is already created, but each user will be able to specify how long to stay on that page and what the next "slide" will be.
So the HTML looks like this: (dashboard.php)
<meta http-equiv="refresh" content="40;url=did-you-know.php">
Right now it is hard coded in but I want to be able to pull it from the database.
So on the dashboard.php file I could have something at the top like: $currentSlide = "Dashboard"; and that way I could add to the query AND slide = $currentSlide so that way I could see that the time is 40 seconds for that slide, so I could stick that in to the content="$time". But my question is, how can I add another query to get the NEXT sort_id so sort_id + 1 and get that filename, so I would have the following information:
slide - time - next_filename
Dashboard - 40 - did-you-know.php
BUT I also need to see if it's the last sort_id and if it is, then the next slide needs to start over at #1.
Does this make sense?
If anyone could help me get in the right direction I would really appreciate it.
Thanks!