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

  • Home
  • SEARCH
  • 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 93295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:19:19+00:00 2026-05-10T23:19:19+00:00

It’s quite possible a question like this has been asked before, but I can’t

  • 0

It’s quite possible a question like this has been asked before, but I can’t think of the terms to search for.

I’m working on a photo gallery application, and want to display 9 thumbnails showing the context of the current photo being shown (in a 3×3 grid with the current photo in the centre, unless the current photo is in the first 4 photos being shown, in which case if e.g. if the current photo is the 2nd I want to select photos 1 through 9). For example, given an album containing the list of photos with ids:

1, 5, 9, 12, 13, 18, 19, 20, 21, 22, 23, 25, 26

If the current photo is 19, I want to also view:

9, 12, 13, 18, 19, 20, 21, 22, 23

If the current photo is 5, I want to also view:

1, 5, 9, 12, 13, 18, 19, 20, 21

I’ve been thinking of something along the lines of:

SELECT * FROM photos WHERE ABS(id - currentphoto) < 5 ORDER BY id ASC  LIMIT 25 

but this doesn’t work in the case where the ids are non-sequential (as in the example above), or for the case where there are insufficient photos before the currentphoto.

Any thoughts?

Thanks,

Dom

p.s. Please leave a comment if anything is unclear, and I’ll clarify the question. If anyone can think of a more useful title to help other people find this question in future, then please comment too.

  • 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. 2026-05-10T23:19:19+00:00Added an answer on May 10, 2026 at 11:19 pm

    Probably could just use a UNION, and then trim off the extra results in the procedural code that displays the results (as this will return 20 rows in the non-edge cases):

    (SELECT       *  FROM photos    WHERE ID < #current_id#    ORDER BY ID DESC LIMIT 10) UNION   (SELECT *    FROM photos    WHERE ID >= #current_id#    ORDER BY ID ASC LIMIT 10) ORDER BY ID ASC 

    EDIT: Increased limit to 10 on both sides of the UNION, as suggested by le dorfier.

    EDIT 2: Modified to better reflect final implementation, as suggested by Dominic.

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

Sidebar

Ask A Question

Stats

  • Questions 235k
  • Answers 235k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer To download something from the Web you could use libcurl… May 13, 2026 at 6:11 am
  • Editorial Team
    Editorial Team added an answer You would have to tweak the CKEditor textarea to write… May 13, 2026 at 6:11 am
  • Editorial Team
    Editorial Team added an answer $(this).parent().children("p.hidden").removeClass("hidden"); May 13, 2026 at 6:11 am

Related Questions

I am currently running into a problem where an element is coming back from
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I want use html5's new tag to play a wav file (currently only supported
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.