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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:55:03+00:00 2026-06-09T22:55:03+00:00

I have taken the working code from this thread: Creating Next and Previous buttons

  • 0

I have taken the working code from this thread:
Creating Next and Previous buttons for navigation

It works for me but right now I would like to ask is there any way to disable the link if it reaches the 1st or the last ID?

Here’s my brief code:

function getNavID($id) {

$result4= mysql_query("SELECT 
( SELECT id FROM products_list WHERE id > '$id' LIMIT 1 )
AS nextValue,
( SELECT id FROM products_list WHERE id < '$id' ORDER BY id DESC LIMIT 1 )
AS prevValue
FROM products_list");
if ($resultID = mysql_fetch_array($result4)) {
    return $resultID;
}
else {
    return NULL;
}
}

$LinkID = getNavID($id);

<p><a href="update.php?id=<?php echo urlencode($LinkID['prevValue']); ?>">Previous</a></p>
<p><a href="update.php?id=<?php echo urlencode($LinkID['nextValue']); ?>">Next</a></p>

Let’s say the page I’m on now is ID=1 so logically, there is no ID lesser than 1. Is there any way that I can do to disable the links if the ID reaches the min and max ID ?

Thanks in advance guys.

Regards,
Jeff

  • 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-06-09T22:55:05+00:00Added an answer on June 9, 2026 at 10:55 pm

    For ID=1, $LinkID['prevValue'] should return NULL, which you can check easily. Include a check, so that you only print the link if there is a previous/next value, e.g.:

    <p>
    <?php
        if (!is_null($LinkID['prevValue'])) {
    >?
        <a href="update.php?id=<?php echo urlencode($LinkID['prevValue']); ?>">Previous</a>
    <?php
        } else {
            echo "No previous entries.";
        }
    ?>
    </p>
    

    And analogously for Next entry.

    By the way, just for completeness’ sake, I would rewrite the SQL statement like this:

    SELECT 
        ( SELECT id FROM products_list
            WHERE id > '$id' LIMIT 1 ) AS nextValue,
        ( SELECT id FROM products_list
            WHERE id < '$id' ORDER BY id DESC LIMIT 1 ) AS prevValue
        FROM products_list
        LIMIT 1
    

    I.e. an additional LIMIT 1 at the end. You might not notice a difference in your result, but with your statement, the database delivers one row per entry in the table products_list (of which you only use the first, and they are all equal).

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

Sidebar

Related Questions

I have taken this little snippet straight out of some code I'm working on:
I have taken over a project that was build from suggestions in this Dan
I have taken a perfectly working MDX piece of code to Windows 2008R2 (all
The following code has been created from a different post, but I now have
I have tried working with a bit of code to decode a file from
I have the following Spring code, taken from a textbook, that's returning a NotWritablePropertyException.
I have taken a manifest from one of the answers posted here in SO
i have a jar file: myServerSide.jar, this jar takes request from client apps, processes
Look at the bottom of this post, for final working code. It's a working
*I'm using Java. I have this thread, agent, that explores a room to determine

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.