| re: Array/Listing/Linking help
Here you go, let me know if you have any questions.
[PHP]
<?php
$emp = array("John Smith","Katie Holmes","Chuck Norris","Joe Blow","Ivana Humpalot","Katie Alvarez");
$empID = isset($_GET['empID'])? $_GET['empID'] : 0; // if empID is in URL get it, if not set it to zero
$previousID = $empID-1;
$nextID = $empID+1;
if($previousID < 0)
{
$previousID = count($emp)-1; // this will go to the end if you go back from the first one (loops), or you can set it zero so that it won't go past zero
}
if ($nextID >= count($emp))
{
$nextID = 0; // this will reset it back to first one if you push next. , or disable it, or set it count($emp) so it doesn't go passed the end
}
?>
<html>
<body>
The employee name is: <?php echo $emp[$empID] ?>
<br/>
<br/>
<a href="testArr.php?empID=<?php echo $previousID; ?>"><< Previous</a> --
<a href="testArr.php?empID=<?php echo $nextID; ?>">Next >></a>
</body>
</html>
[/PHP]
Dan
|