I have a huge database and need to sort by first letter, basically A-Z. This is what I have so far , but it gives me ALL the results.
$result = mysql_query("SELECT Distinct id,name FROM table WHERE name REGEXP '[A-Z]' ORDER BY name ")
or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
$id=($row['id']);
$name=substr($row['name'],0,1);
echo "<a href=\"page.php?id=" .$id. "&name=" .$name. "\"> $name</a>\n";
}
The result of this looks something like this, but thousands more:
AAAA
AAAA
AAAA
AAAA
BBBB
BBBB
etc..
What do I need to do to just have one of each letter and then obviously when that letter is clicked it show results for all rows in that particular letter?
Thanks.