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 6803329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:19:52+00:00 2026-05-26T19:19:52+00:00

I am trying to make a photo gallery in php + mysql. The URL

  • 0

I am trying to make a photo gallery in php + mysql.

The URL viewphoto.php?id=143 shows photo 143.
In the navigation menu, I want to display the previous two photos in that album, and the next two.

I thought of using:

$temp_id = $id - 2;
mysql_query("SELECT id, photo FROM photos WHERE album = {$album} AND id >= {$temp_id} LIMIT 5");

But that didn’t work, because photo’s from different albums could have the ids preceding and succeeding the one of the viewed photo.

Does anyone know how I could do this?

Thanks.

  • 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-26T19:19:53+00:00Added an answer on May 26, 2026 at 7:19 pm

    I’ve been dealing with this issue myself and I never found an elegant solution to the problem, I ended up doing it in two queries:

    // next
    mysql_query("SELECT id, photo FROM photos WHERE album = {$album} AND id > {$id} ORDER BY id ASC LIMIT 2");
    
    // prev
    mysql_query("SELECT id, photo FROM photos WHERE album = {$album} AND id <= {$id} ORDER BY id DESC LIMIT 3");
    

    Now the first item in “prev” once fetched would be the current photo.

    This solution does has to be amended with a check that the first item in “prev” is in fact the requested id, because it doesn’t make sure it’s the proper id, in case of gaps in the series.

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

Sidebar

Related Questions

I'm currently trying to make a photo gallery application where photos are only accessible
Im trying to make a wordpress widget containing a jquery photo gallery. The widget
I am trying to make little photo gallery with help of model view. But
I'm trying to make my application grab a photo from the user's Photo library
Trying to make a floating css menu. How do I get the floating div
Trying to make a toggle button that hides/shows the right window/pane. Here is a
I'm trying to make category changes with Jquery & Php. I have no problem
What I'm trying to do is basicly what this photo shows. When I select
I'm trying to make a photo feed for an app I'm making, similar to
I am trying to make a function in PHP that will allow me to

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.