How to Create Alphabetical Lists

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sree78
Forum Commoner
Posts: 39
Joined: Tue May 20, 2003 11:38 am

How to Create Alphabetical Lists

Post by sree78 »

Hi people,

I am a newbie just starting to code in PHP. I was using coldfusion until my boss decided to go into PHP. I want to create a alphabetical lists which will pass each each letter variable to another page which will be then queried and produce the results for that alphabet.

A B C D E F

What I have rite now:-

<?php
$i="A";
echo "<a href="employee_details.php?i=$i>A</a>";
?>


Not sure if this is right . Pls guide me. Thanks :roll:
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

Post by daven »

Code: Select all

<?php
$i="A";
echo "<a href="employee_details.php?i=".$i."">".$i."</a>"; 
# repeat for C,D,etc.
?>
That should work. You were just missing some quotes in your line.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You could also do:

Code: Select all

echo '<a href="employee_details.php?i='.$i.'">'.$i.'</a>';
instead of

Code: Select all

echo "<a href="employee_details.php?i=".$i."">".$i."</a>";
so you don't have to escape those double quotes in the HTML.

Have a read of:
http://www.php.net/manual/en/language.types.string.php

As for creating a linked alphabet, you could do something like:

Code: Select all

<?php

for ($i = 'A'; $i != 'AA'; $i++) {
	echo '<a href="employee_details.php?i='.$i.'">'.$i.'</a>';
}

?>
Mac
sree78
Forum Commoner
Posts: 39
Joined: Tue May 20, 2003 11:38 am

Post by sree78 »

:P

Thanks a lot for the help.. It worked perfectly..
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

http://www.php.net/asort might be of interest to you
Post Reply