Entry
How to make a GoBackButton with a picture?
Feb 19th, 2008 22:03
dman, Dan Stockton, Dan Stockton, Philip Olson, Pieter W.D. Kroon, http://www.ttnr.org
A couple of ways :
First, using LIMITs will work, so :
[go back] : http://www.example.com/picture.php?start=10
-current- : http://www.example.com/picture.php?start=20
[go forward] : http://www.example.com/picture.php?start=30
This example would have 10 pics per page and most likely use the SQL
LIMIT statement to control output. Essentially something like this :
// the 10 here means '10 per page'. $start is the first
// record pulled, the 'offset' number
$sql = "SELECT * from photos LIMIT $start,10";
A link could be created as such, assuming no back button is to exist
when start = 0 :
if ($start != 0) {
print '<a href="pics.php?start='. ($start-10) .'">go back</a>';
}
Also, make sure $start exists, so on top of page :
if (empty($start)) { $start = 0; }
A more detailed approach to the above can be found here :
Building Next/Prev Buttons for Query Results (part 2) :
http://phpbuilder.com/columns/rod20001214.php3
Or, use JavaScript :
<a href="javascript:history.go(-1)">[ back ]</a>
Which will go back in the users history.
or, use a global http_server_variable
(you must define this variable first);
<a href="<?global $HTTP_REFERER;echo $HTTP_REFERER;?>"><img
src="the_page_you_came_from.gif"></a>
.. OR you could:
use either of the above two options with a form:
<form>
<input type="image" title="Go Back" src="image.png"
onclick="javascript:history.go(-1)">
</form>
<form action="<?$_SERVER['HTTP_REFERER'];echo $_SERVER['HTTP_REFERER'];?>">
<input type="image" title="Go Back" src="image.png">
</form>
NOTE:
(from php.net/manual)
".. you'll notice how the older predefined variables ($HTTP_*_VARS)
still exist. As of PHP 5.0.0, the long PHP predefined variable arrays
may be disabled with the register_long_arrays directive."
that's what it says on the
I haven't used 5.* yet but I've looked through the changelog and it
doesn't appear that they've gotten completely rid of the 'global
http_server_variable' yet.
YMMV