Jump to content


Photo

Dynamic alphabetical listing (menu)


  • Please log in to reply
No replies to this topic

#1 garwil

garwil
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 04 March 2006 - 10:09 PM

Hi,
Am using Dreamwever MX 2004 and trying to create an alphabetical listing menu from a 'countries' Mysql DB. At the moment there are something like 264 countries and I wish for the alphabetical listing to indicate by way of a different font colour, those items that have a country. e.g. the letter 'S' will turn RED if there are any countries in teh database beginning with that letter. When the letter 'S' is clicked the url will invoke a search, pulling all the countries beginning with 'S' into a details page. At this point in time my 'countries'db consists of 5 tables, being ID, cntry_code, flag_loc, map_loc and name.
I am using this code below but all I receive is the alphabetical listing at the top of the page. Can anyone help me?
<?php require_once('Connections/apt.php'); ?>
<?php
mysql_select_db($database_apt, $apt);
$query_countries = "SELECT DISTINCT UPPER(LEFT (name,1)) FROM countries ORDER BY name ASC";
$countries = mysql_query($query_countries, $apt) or die(mysql_error());
$row_countries = mysql_fetch_assoc($countries);
$totalRows_countries = mysql_num_rows($countries);

$alphabet=('A B C D E F G H I J K L M N O P Q R S T U V W X Y Z');
$query=mysql_query("select distinct(name) FROM countries");
while ($r=mysql_fetch_array($query)) {
$initial=$r['name'];
$links=str_replace("$name","<a href=\"$test2.php\">$name</a>",$alphabet);
}
echo("$links");
?>
<body>
<?php
mysql_free_result($countries);
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users