Connecting Tech Pros Worldwide Forums | Help | Site Map

Array/Listing/Linking help

Newbie
 
Join Date: Oct 2008
Posts: 1
#1: Oct 25 '08
Hello,

I am working on an array that holds ID numbers for a list of employees. This is what I have:
[PHP]<?php

$uniqueID = array();

$uniqueID(0) = 11102487;
$uniqueID(1) = 11194710;
$uniqueID(2) = 11237894;
...
$uniqueID(127) = 94512796;

?>[/PHP]

What I want to do, is have it read from the above list. The web site would have a previous and next button.

So as default, Previous would be disabled, and then ID(0) would show. Next would go to ID(1), and then ID(2), etc. Each ID has it's own .php page. So what I want is, a next button that would be like, <a href="$uniqueID(1).php">Next</a> and have the number in the () increment by 1 per click. I know a counter would be needed, and a loop, but I'm not sure where everything should go. I'm a PHP n00b.

Any suggestions/snippets that'll point me in the right direction?

Thanks!

dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,095
#2: Nov 1 '08

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
Reply


Similar PHP bytes