title: How can I get the nearest rows in mysql?
body: <p>Lets say I'm trying to build a thumbnail of some gallery (5 thumbnails showing). How can I get my mysql to display 5 thumbnails, the middle thumbnail will be the image blown up, and the two on the left of the middle will be previous images, and the two other images on the right of the middle will be 2 more images after.</p>
  
  <p>EDIT</p>
  
  <hr>
  
  <p>I know how to easily get 5 thumbnails with something like this</p>
  
  <pre><code>$sqlThumb = mysql_query("SELECT iID,thumbnails,userID FROM images WHERE userID = ".$_SESSION['userID']." ORDER BY iID ASC LIMIT 1,5");
  </code></pre>
  
  <p>But the thing is, I dont have a consistent id (meaning, there will be deleting and inserting). It is based on the images that the user has. </p>
  
  <pre><code>iID            userID 
  -----          --------
  1              5
  2              4
  3              4
  4              5
  5              5
  6              5
  10             5
  11             5
  12             5
  </code></pre>
  
  <p>So if a user clicks an image which shoes iID number 5, the thumbnail should show like this in order, 1,4,5,6,10.</p>
  
  <p>However, also if a user clicks on thumbnail number 10, the thumbnail should show: 5,6,10,11,12.</p>