faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

14 of 19 people (74%) answered Yes
Recently 7 of 10 people (70%) answered Yes


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) :
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 
.. OR you could:
use either of the above two options with a form:
<input type="image" title="Go Back" src="image.png"
<form action="<?$_SERVER['HTTP_REFERER'];echo $_SERVER['HTTP_REFERER'];?>">
<input type="image" title="Go Back" src="image.png">
(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.