Jump to content

Recommended Posts

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?[code]<?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);
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/4114-dynamic-alphabetical-listing-menu/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.