Hi there,
I'm still very new to PHP and wondered if you could help.
Heres the situation...
I have 8 web pages. index.php, page2.php, page3.php etc..
These include a header.html and footer.html (in an "includes" folder).
I'd like to have a simple "next page" and "previous page" links at the top of every page.
So I created a functions.php and put that in the "includes" folder.
In the header.html I call the function np()
Now this is the way I thought I could do it (probably the wrong way!)....
* find the page we're on
* locate position in the array (The site will never be very big so I can just add the page to this array if I create more in the future)
* make next and previous buttons +1 and -1 of that position
* if at the end of array, loop to the beginning.
I've been trying various different ways of doing this, but I''m not very good.PHP Code:function np(){
$url = array(
'index' => 'index',
'page2' => 'page2',
'page3' => 'page3',
'page4' => 'page4',
'page5' => 'page5',
'page6' => 'page6',
'page7' => 'page7',
'page8' => 'page8'
);
foreach ($url as $key => $value){
if($_SERVER['PHP_SELF'] == "$key.php"){
/*Here's where I thought I could state that
$next would be the $key +1 of the array index and
$previous would be the $key -1 of the array index
I'd also like it to loop around when the user pressed
next on page8.php it would go to index.php*/
}
else{
//not sure what I'd put here!
}
}
}
So this is my last resort, please could someone help me write this code?
Any help is much appreciated.
Steve




Bookmarks