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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:26:11+00:00 2026-06-05T09:26:11+00:00

Based on Hunter F’s answer, the solution to my problem is almost complete. Just

  • 0

Based on Hunter F’s answer, the solution to my problem is almost complete.
Just a couple of tweaks needed.

I modified the code a little and submitted a new question here at: php array help required – if current array item = 'last or first item' then 'do something'

ORIGINAL MESSAGE:

I want to be able to create a simple navigation bar with PREV and NEXT links that I can use to cycle though a list of pages. The navigation bar will be a php include within all of the pages to be cycled.

So I guess the starting point is to create an array of the pages that need to be cycled though with the PREV NEXT links.

Such as….

$projectlist = array(
        'http://domain.com/monkey/',
        'http://domain.com/tiger/',
        'http://domain.com/banana/',
        'http://domain.com/parrot/',
        'http://domain.com/aeroplane/',
);

I want to option to re-order, add or remove the links. So having one self contained master array such as this seems like a logical choice to me as I’ll only need to update this one list for any future additions.

Each directory being linked to has it’s own index.php file, so I’ve left the index.php part off from the end of the links as it’s not needed…or is it?

…I’m pretty stumped as of how to continue from here.

I guess I need to work out which page within the array I’m currently on, then generate the PREV and NEXT links based on that. So If I entered from ‘http://domain.com/parrot/‘ I would need links to the relevant PREV and NEXT pages.

Any help or information to guide me on this next stage would be most appreciated.

  • 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-05T09:26:12+00:00Added an answer on June 5, 2026 at 9:26 am
    $currentPath = explode('?', $_SERVER['REQUEST_URI']); //make sure we don't count any GET variables!
    $currentPath = $currentPath[0]; //grab just the path
    $projectlist = array(
            '/monkey/',
            '/tiger/',
            '/banana/',
            '/parrot/',
            '/aeroplane/',
    );
    if(! in_array($currentPath, $projectlist) ) {
        die('Not a valid page!'); //they didn't access a page in our master list, handle error here
    }
    $currentPageIndex = array_search($currentPath, $projectlist);
    
    if($currentPageIndex == 0) { //if it's on the first page, we want them to go to the last page
        $prevlink = '<a href="'.$projectlist[ sizeof($projectlist)-1].'">Prev</a>';
    } else { //otherwise just go to the n-1th page
        $prevlink = '<a href="'.$projectlist[$currentPageIndex-1].'">Prev</a>';
    }
    
    
    if($currentPageIndex  == sizeof($projectlist)-1 ) {     //if we're on the last page, have them go to the first page for "next"
        $nextlink = '<a href="'.$currentPageIndex[0].'">Next</a>';
    } else {
        $nextlink = '<a href="'.$projectlist[$currentPageIndex+1].'">Next</a>';
    }
    

    One thing you may want to consider, is urlencoding the href targets in the link.

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

Sidebar

Related Questions

Based on the answer from axtavt, this is almost certainly a naming problem between
Based the accepted answer to this question I've setup a NetBeans/tomcat environment. In testing
Based on some standard web searching, I have narrowed down my problem to this:
Based on code suggestions here at stackoverflow, I've tried to extract an image from
Based on This solution I am trying to develop a script that would limit
based to your experience, what kind of technical solution will you apply to build
based on Google I managed to write a little Groovy script that packs a
It's just been one problem after another today. I just deployed to my production
Based on some other code I found from this site (This Question here -
Based on my reading, the following code: string aggregate = give + 'n'; Should

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.