Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm going to add to Frankie's answer, because I also believe the OP's current method is going to bite him the butt again one day. The OP may not find this useful, but it could help someone else.</p> <p>You can use <a href="http://site.com/images/20" rel="nofollow">http://site.com/images/20</a>, but the 20 represents an image ID instead of a page number. Of course the query to get the image is simple:</p> <pre><code>SELECT id, img_src FROM pictures WHERE gallery = images AND id = 20 LIMIT 1 </code></pre> <p>As a benefit this query is more efficient than using an offset with the LIMIT clause. But the OP said in a comment that he likes his current system because it doesn't require additional database queries to help build pagination links. Well, that's not a problem here.</p> <p>Lets say you're on the page <a href="http://site.com/images/20" rel="nofollow">http://site.com/images/20</a>. Your page links would be the following:</p> <p>Prev - <a href="http://site.com/images/prev/20" rel="nofollow">http://site.com/images/prev/20</a> Next - <a href="http://site.com/images/next/20" rel="nofollow">http://site.com/images/next/20</a></p> <p>Obviously it didn't take any additional queries to build those links. They're just a slightly different URL showing the same image ID. But how do they work to move to the next or prev image? Simple. Instead of the above query, you would use one of these:</p> <p>If the prev link was clicked, you use this query:</p> <pre><code>SELECT id, img_src FROM pictures WHERE gallery = 'images' AND id &lt; 20 ORDER BY id DESC LIMIT 1; </code></pre> <p>If the next link was clicked, you use this query:</p> <pre><code>SELECT id, img_src FROM pictures WHERE gallery = 'images' AND id &gt; 20 ORDER BY id ASC LIMIT 1; </code></pre> <p>The first query gives the image that came before the current one, and the second query gives the image that comes after the current one.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload