Page 1 of 1

How to Create Alphabetical Lists

Posted: Tue May 20, 2003 11:38 am
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:

Posted: Tue May 20, 2003 12:39 pm
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.

Posted: Tue May 20, 2003 1:08 pm
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

Posted: Fri May 23, 2003 11:30 am
by sree78
:P

Thanks a lot for the help.. It worked perfectly..

Posted: Fri May 23, 2003 4:05 pm
by m3mn0n
http://www.php.net/asort might be of interest to you