Forum Moderators: coopster

Message Too Old, No Replies

Dynamic Anchor based on last name

How can I create a dynamic anchor for employee listing?

         

seanp

2:58 pm on Apr 5, 2004 (gmt 0)



I have a MySQL database that hold the list of employees. I display the page using PHP. All of this works great, I sort by last name ascending so the list is A-Z.

Here is what I want to do.

At the top of the page I want to list each letter of the alphabet and have it as a link. From that link (lets say "G") when I click on G it jumps to the first employee that has a last name that starts with G (staying on the same page)

Is there some way to create a dynamic anchor that would jump to a specific areas based on how the alphabet link was coded?

barn_de

3:12 pm on Apr 5, 2004 (gmt 0)

10+ Year Member



Hi seanp,

this could help you. i just wrote it in 2 min. but i tested it and it works.

foreach ( $aEmployees as $aEmployee ) {
$sLetter = substr($aEmployee['last_name'], 0, 1);

if ($sLetter!= $sLetterOld) {
echo '<a name="' . $sLetter . '"></a>' . "\n";
}
echo $aEmployee['first_name'] . ' ' . $aEmployee['last_name'] . '<br>' . "\n";
$sLetterOld = $sLetter;
}

hope this helps

barn