title: best way for next/previous buttons for entries in yii
body: <p>I would like to know what is the best way to create next/previous buttons for an entry in the database.
  Let's say we have a table with images and every image has an ID and a Path.
  If the current image has ID equal to "9" how can I get the next and the previous IDs?</p>
  
  <p>I already found a solution for this right here
  <a href="https://stackoverflow.com/a/8874382">https://stackoverflow.com/a/8874382</a>
  but this seems to be the latest choice. If we have over 10000 entries (images) in our database, this will overwhelm the server. First of all, it selects all entries and then it tries to copy all of the results in an array. After this, the array is searched for the current ID. It's very slow.</p>
  
  <p>I was thinking about a limit set to the query but how can I get the next and previous pictures after this? </p>
  
  <p>Another (better, I think) solution would be to get the ID of the current picture and decrement/increment it until another image with the new ID is found. I think this is faster than the function provided in the link.</p>
  
  <p>Also, in the same link there is another idea, to set the prev_id and next_id in the model of the current picture. But here we have the same problem, how do we find them? And even if we find them, is it correct to store data about prev/next pictures in the current picture? It does not seem to be right but I'm sure it's more convenient when you need to access that data. </p>
  
  <p>Thank you!</p>