Alphabetical listing group by alphabet in php
mysql, php
Solution
Maybe it is a bad way to do it, but it can help you now.
<?php
$aGroup = array(
"A" => array(),
"B" => array(),
"C" => array(),
"D" => array(),
"E" => array(),
// until "Z"
);
$result = mysql_query("SQL as you want");
while ($row = mysql_fetch_array($result)) {
$letter = strtoupper($row[0][0]); // I supose that the first column is the name
$aGroup[$letter][] = $row;
}
?>
Problem
I have a member table where I am storing all details about a member including its name, email, phone etc. I want the name will appear as a alphabetical group wise. Such as shown in example. ``` A Alan Alex Amar Andy B Bob Brad C Calvin Clerk D E ``` I can sort the field alphabetically using order by ASC but how do I get them in group of alphabet. Any suggestions are most welcome. I am using php.