Re: Looking for code for an alphabetic menu in php
| From: | Sascha Meyer | Date: | Fri, 22 May 2009 08:23:19 +0000 |
| Subject: | Re: Looking for code for an alphabetic menu in php | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-29345@lists.php.net to get a copy of this message | ||
Hi Bill,
I don't know if I got you right but I hope this will help:
[CODE]
<?php
$baseLink = "index.php?letter="; // Assuming your file name is "index.php"; set up the base link for all pages
//alphabetical links
for($a=65;$a<(65+26);$a++){
print "<a href=\"".$baseLink.chr($a)."\">".chr($a)."</a>\n";
}
if (isset($_GET["letter"]) && $_GET["letter"] != ""){
$letter = $_GET["letter"];
$sql = "SELECT * FROM species WHERE [SPECIES_NAME] LIKE '".$letter."%'"; // Replace [SPECIES_NAME] with your column name
$res = mysql_query($sql);
if ($res){
while ($row = mysql_fetch_row($res)){
// retrieve your row info
}
} else {
print "Failed retrieving data set, error was: ".mysql_error();} } ?> [/CODE] Enjoy, Sascha Bill Mudry schrieb:
With the botanical wood tree that I have been working on, the number of records for genera and for species can get quite large and unwieldy. Presently I have over 6,000 species records that takes a while to load let alone try to browse through. I need to chop this up into querying by alphabet of the first letter of the species botanical names. For the species level of organization, I have been keeping the data in a MySQL file called simply 'species'. I want to have a single character of the alphabet with each acting as a link for the first character of each species name: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 When a user click on one of them, it should be readable (eg. using $_GET??) into a common variable for them all that can then be used for a select statement. The rest of displaying theresults in columns I already have working fine. What suggestions do you have for typical code that should work? Much thanks in advance, Bill Mudry Mississauga, Ontario, Canada