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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:13:17+00:00 2026-05-24T17:13:17+00:00

I have set up my code to get the previous and next id. But

  • 0

I have set up my code to get the previous and next id. But once it hit the last or beginning of the numbers, it won’t let me go next or previous, respectively.

This is how I set my sql query

$pre = mysql_query("SELECT iID,userID FROM images WHERE iID < # AND userID = 4 ORDER BY iID DESC LIMIT 1"); 
$nex = mysql_query("SELECT iID,userID FROM images WHERE iID > # AND userID = 4 ORDER BY iID ASC LIMIT 1");

Can someone help me cycle the query? So if it hits the lowest number, or the largest number, it will go back cycle

ex:

iID     userID

3        4
4        0
5        4
10       4

So if I cycle through all the userID with 4 and currently it will show iID, 5, I can click previous and next and it will then go to iID 3 and 10, respectively. But when it hits 3 or 10, it is the max. I would like to continue through the query. So if I hit previous, it will go 3, and if I hit previous again, it will go to 10, and then 5, and then 3, then back to 10…

Can someone help me?

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-24T17:13:20+00:00Added an answer on May 24, 2026 at 5:13 pm

    If you get the min and max iID’s you have a range you can check from

    UPDATE (this should return two values min/max):

    SELECT MAX(iID) AS max_iid, MIN(iID) AS min_iid
    FROM images
    WHERE userID = 4
    

    PHP:

    // Check if image is between the min/max
    if($iID <= $max_iid && $iID >= $min_iid) {
        // display image
    
    // if image id is greater than the max, display the min id
    } elseif($iID > $max_iid) {
        // display min_iid image
    
    // else display the max image id
    } else {
        // display max_iid image
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have my code set to disable the submit button when the field
I am having a bit of difficulty with this current code I have set
Anyone have code to set margins(top,left,right,bottom) using excel interop and vb.net. I think it
I have the following code set up in my Startup IDictionary<string, string> properties =
I have a problem with this is code: Set oXmlHTTP = CreateObject(Microsoft.XMLHTTP) oXmlHTTP.Open POST,
I have a View with ViewModel as datacontext ( set in code) . In
I have the following code to set a userId variable: (userId set in prior
I have java script code to set some of the properties of ajax controls.
I currently have CruiseControl.NET set up with SVN to automatically grab the code source
I have some code that produces a set of primary key values that I

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.