Forum Moderators: open
I tried to read the result as an array and use array_unique() which does not work for being within the loop each letter results in an array of its own and not in only one single array
$query = "SELECT UPPER(SUBSTRING(`username`,1,1)) AS letters FROM `profile` GROUP BY letters ORDER BY letters ASC";
echo $query;
$result=mysql_query($query);
echo '<select name="letters">';
while ($row=mysql_fetch_array($result) )
{
echo '<options value="'.$row['letters'].'">'.$row['letters'].'</option>';
}
echo '</select>';
Thanks
something else is echoed in phpMyAdmin
it reads:
the usual ->T<-
below it is the word: letters
and below letters:
a single cap letter: U which I believe comes from the first letter of username?
note: in the test col (username) nothing starts by or even contains a "u"
$query = "SELECT DISTINCT UPPER(SUBSTRING(username,1,1)) AS letters FROM profile ORDER BY letters ASC";
and then the rest of the code you have
the reason you get 0 records is cause you use
SUBSTRING(`username`,1,1)), which becomes a variable letters.
when you place the item in single quotes in SQL query it is treated as string and not a column name, so it creates a string 'U', wich is the first character in string 'username'(and then you sort by 'U').
that is not what you want.
you want distinct first letter in column username from table profile sorted ASC
give it a try.
blend27