Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP and MySQL: Formatting URLs correctly when using pagination to display images of multiple galleries
    primarykey
    data
    text
    <p>I've set up a simple gallery system in PHP that is built to display one image per page. My URL parameter simply uses a gallery variable and a page variable and does not use the image iD in any way to pull the image. This is because I'm setting my htaccess settings to make a friendly URL:</p> <pre><code>http://mysite.com/images/1/ </code></pre> <p>^ Would pull the first image in my MySQL query</p> <p>or</p> <pre><code>http//mysite.com/images/12/ </code></pre> <p>^ Would pull the 12th image in my MySQL query</p> <p>The PHP page would then look like:</p> <pre><code>images.php?gallery=images&amp;page=1 </code></pre> <p>and</p> <pre><code>images.php?gallery=images&amp;page=12 </code></pre> <p>The queries (simplified) would then look like this for each of the above:</p> <p>For the first image:</p> <pre><code>SELECT id, img_src FROM pictures WHERE gallery = images ORDER BY date_added DESC LIMIT 0, 1 </code></pre> <p>and for the 12th image:</p> <pre><code>SELECT id, img_src FROM pictures WHERE gallery = images ORDER BY date_added DESC LIMIT 11, 1 </code></pre> <p>It's been working great but I ran into a problem now that I want to add a feature. I was hoping to display thumbnails of the ten most recently added images to the database no matter which gallery they belong to… i.e. this query:</p> <pre><code>SELECT id, gallery, img_src FROM pictures ORDER BY date_added DESC LIMIT 10 </code></pre> <p>Is there any way I can know which 'position' or 'page' each image would be for the specific gallery so that I can create the link correctly?</p> <p>For example, say the ten most recent thumbnails return 4 pictures from the gallery 'images', then 2 pictures from the gallery 'weddings', then 3 pictures from the gallery 'portraits' and then one more image from the gallery 'images', so my links should then be:</p> <pre><code>http://mysite.com/images/1/ http://mysite.com/images/2/ http://mysite.com/images/3/ http://mysite.com/images/4/ http://mysite.com/weddings/1/ http://mysite.com/weddings/2/ http://mysite.com/portraits/1/ http://mysite.com/portraits/2/ http://mysite.com/portraits/3/ http://mysite.com/images/5/ </code></pre> <p>Thanks for any help. I'm sure I'm overlooking something stupid easy here but I'm hoping to do it most efficiently as far as programming goes. So far my thoughts are that when I'm looping through the output I have to somehow retain each gallery's 'image count' and add one to this count each time an image of that gallery is added. </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.
 

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