Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3283320
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:01:37+00:00 2026-05-17T20:01:37+00:00

I’ve set up a simple gallery system in PHP that is built to display

  • 0

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:

http://mysite.com/images/1/

^ Would pull the first image in my MySQL query

or

http//mysite.com/images/12/

^ Would pull the 12th image in my MySQL query

The PHP page would then look like:

images.php?gallery=images&page=1

and

images.php?gallery=images&page=12

The queries (simplified) would then look like this for each of the above:

For the first image:

SELECT id, img_src 
FROM pictures 
WHERE gallery = images
ORDER BY date_added DESC 
LIMIT 0, 1

and for the 12th image:

SELECT id, img_src
FROM pictures 
WHERE gallery = images 
ORDER BY date_added DESC 
LIMIT 11, 1

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:

SELECT id, gallery, img_src 
FROM pictures
ORDER BY date_added DESC
LIMIT 10

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?

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:

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/

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:01:43+00:00Added an answer on May 17, 2026 at 8:01 pm

    Quick and dirty:

    $sql = "SELECT id, gallery, img_src 
    FROM pictures
    ORDER BY date_added DESC
    LIMIT 10";
    
    $result = mysql_query($sql);
    
    while($row = mysql_fetch_assoc($result)) {
        if(!$$row['gallery']) $$row['gallery'] = array();
        array_push($$row['gallery'], $row['id']);
        $pagenumber = count($$row['gallery']);
        echo "<a href=\"http://mysite.com/{$row['gallery']}/$pagenumber/\">
            <img src=\"{$row['img_src']}\" alt=\"\"></a><br>";
            // alt attribute for w3 validation (http://validator.w3.org/)
    }
    

    Edit:

    Fixed code error. Now will dynamically create the array if it doesn’t already exist.
    (Originally, it illegally used the [ ] operator.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.