Liam Delahunty: Home Tips Web Contact
Recommended laptop
under £500
.

Think I deserve a present? See my Amazon Wish List

PHP Forward Next with multi-dimensional arrays

The first dimention in the array if for the filename of the page. The second for the link name.

This code would be in an include page for the section.


$prev_next_array[] = array("2002q1", "1st Quarter 2002");
$prev_next_array[] = array("2002q2", "2nd Quarter 2002");
$prev_next_array[] = array("2002q3", "3rd Quarter 2002");
$prev_next_array[] = array("2002q4", "4th Quarter 2002");
$prev_next_array[] = array("2003q1", "1st Quarter 2003");
$prev_next_array[] = array("2003q2", "2nd Quarter 2003");
$prev_next_array[] = array("2003q3", "3rd Quarter 2003");

$url = eregi_replace(".php$","",$PHP_SELF);
$split = split("/",$url);
// go to last element
$mykey = end($split);

// Now I know what page I'm on

$count = count ($prev_next_array);
for ($i=0; $i<$count; $i++){
   print ("<p>");
   if ($prev_next_array[$i][0] == $mykey){
      if ($i>0){
         $prev=$i-1;
         print ("<a href=\"" . $prev_next_array[$prev][0] . ".php\">".$prev_next_array[$prev][1]."</a>");
      }else{
         print ("<a href=\"index.php\">Home</a>");
      }
      // this page
      print (" | <b>".$prev_next_array[$i][1]."</b> | ");
      if ($i < $count-1){
         $next=$i+1;
         print ("<a href=\"" . $prev_next_array[$next][0] . ".php\">".$prev_next_array[$next][1]."</a>");
      }else{
         print ("<a href=\"index.php\">Home</a>");
      }
   }
   print ("</p>");
}

Share this!  



Php Php Self Non Printable Character | Php Prev Next Array | Php Prohibit Access To Pages Based On Ip Address


 

  Tips | Home | Search | Contact

Link here: