Alphabetical Listing
Posted: Fri Jul 18, 2003 5:44 am
Hi Folks,
Something quite simple, that I can't think how to solve.
I've got a list of PLACES, which I need to list in alphabetical order. That's the easy bit:
What I'd like to do, is have at the top of the page, a menu, with letters A to Z, and using name/hrefs be able to jump up and down the list. The only way I can do it so far is:
$letter[] is predefined with letters A to Z corresponding to 1 to 26.
I've found this is quite process intensive as it runs 26 different sql queries. Is there an easier way?
Hope someone can help......
Something quite simple, that I can't think how to solve.
I've got a list of PLACES, which I need to list in alphabetical order. That's the easy bit:
Code: Select all
$places_sql="select * from places where ".$reference."='".$reference_id."' ORDER BY PLACE";
$places_result=mysql_query($places_sql,$connect);
while ($places=mysql_fetch_array($places_result)) {
echo("<li><a href="explore.php?type=place&PLACE_NO=".$placesї"PLACE_NO"]."">".stripslashes($placesї"PLACE"])."</a></li>\n");
}Code: Select all
FOR ($counter=1;$counter<27;$counter++) {
echo("<li><a name="".$letterї$counter].""></a></li>");
$places_sql="select * from from places where ".$reference."='".$reference_id."' AND PLACE LIKE '".$letterї$counter]."%' ORDER BY PLACE";
$places_result=mysql_query($places_sql,$connect);
while ($places=mysql_fetch_array($places_result)) {
echo("<li><a href="explore.php?type=place&PLACE_NO=".$placesї"PLACE_NO"]."">".stripslashes($placesї"PLACE"])."</a></li>\n");
}
echo("<li> Return to <a href="#top">Top</a></li>");
}I've found this is quite process intensive as it runs 26 different sql queries. Is there an easier way?
Hope someone can help......