Connecting Tech Pros Worldwide Help | Site Map

Array/Listing/Linking help

 
LinkBack Thread Tools Search this Thread
  #1  
Old October 25th, 2008, 04:47 AM
Newbie
 
Join Date: Oct 2008
Posts: 1
Default Array/Listing/Linking help

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!
Reply
  #2  
Old November 1st, 2008, 05:07 PM
dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Age: 24
Posts: 899
Default

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
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.