By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,746 Members | 1,928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,746 IT Pros & Developers. It's quick & easy.

Array/Listing/Linking help

P: 1
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!
Oct 25 '08 #1
Share this Question
Share on Google+
1 Reply


dlite922
Expert 100+
P: 1,584
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
Nov 1 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.