I will label my pages like so 1.php 2.php 3.php 4.php Ect Is there a script which i can link to a next page button so 3.php will go to 4.php and another one so i can link a previos page button so 5.php will go to 4.php ? The full address will be someting like http://www.address.co.uk/folder/folder/1.php http://www.address.co.uk/folder/folder/342.php Can anyone help ? Thankyou
You could try something like this (off the top of my head): $this = basename($_SERVER['SCRIPT_URI'], '.php'); $prev = $this - 1; $next = $this + 1; $prevlink = $prev . '.php'; $nextlink = $next . '.php'; PHP: You will need to add your own code to check that $prev is never less than 1 and $next is never greater than the last page. Hope that helps... Cryo.
Heh, you don't get much more simpilar then that. Just increment the current value by 1 for the next page, and decrement the current value for the last page, unless the page is already 1 or max.
Put the this where ever you want your next / prev links to be located: <? $this = basename($_SERVER['SCRIPT_URI'], '.php'); $prev = $this - 1; $next = $this + 1; $prevlink = $prev . '.php'; $nextlink = $next . '.php'; echo "<a href=$prevlink><< Previous</a> | <a href=$nextlink>Next >></a>"; ?> Code (markup):
Take my block of code and put it in the Files exactly where you want your NExt and Previous links to appear.
This code doesnt work... It only directes people to pages 1 and -1 ??? shown here ... http://www.geekazoid.co.uk/Funny-Pictures/Pages/38.php
Great postings... I'm looking to do the same thing with results from a search... Something that when you select one of the search pages, you can hit next from the selected page to go to the next result... Will be something working on soon... so look forward to the solution... Thanks, Starke
This might work better: $this = basename($_SERVER['SCRIPT_URI'], '.php'); $prev = intval($this) - 1; $next = intval($this) + 1; $prevlink = $prev . '.php'; $nextlink = $next . '.php'; echo "<a href=\"$prevlink\"><< Previous</a> | <a href=\"$nextlink\">Next >></a>"; PHP:
Nope, that code must be incorrect The same thing is happening Its not doing any calculation its just linking to 1 and -1 ???? http://www.geekazoid.co.uk/Funny-Pictures/Pages/38.php
Try using 'PHP_SELF' in place of 'SCRIPT_URI'. If you're still having problems, print out the value of $this after the first line.
<?php $prev = basename($_SERVER['REQUEST_URI'], '.php') - 1; $next = basename($_SERVER['REQUEST_URI'], '.php') + 1; $prevlink = $prev . '.php'; $nextlink = $next . '.php'; echo "<a href=\"$prevlink\"><< Previous</a> | <a href=\"$nextlink\">Next >></a>"; ?> Code (markup): He had SCRIPT_URI and not REQUEST_URI mine should work now.
Brilliant thats working ! now is there anyway i can get the next and previous to link be images ?? So the images would link to the next page and the previous page ?
<?php $prev = basename($_SERVER['REQUEST_URI'], '.php') - 1; $next = basename($_SERVER['REQUEST_URI'], '.php') + 1; $prevlink = $prev . '.php'; $nextlink = $next . '.php'; echo "<a href=\"$prevlink\"><img src=\"prev.gif\" border=\"0\"></a> | <a href=\"$nextlink\"><img src=\"next.gif\" border=\"0\"></a>"; ?> Code (markup): remember the prev.gif and next.gif must be located in the same folder as your php files; if they are some where else simple modify the src part and it will work to your needs.