Looking to list mysql result in json. Needs to be alphabetical
json needs to be like this:
[
{
"letter": "A",
"result": [
{
"name": "A&W"
}
]
},
{
"letter": "B",
"result": [
{
"name": "Best Buy "
}
]
}
]
Need to group mysql results and add them under "result" for the appropriate letter. Based on the first letter of the "name" column in mysql.
heres my code:
$sql = "SELECT name AS nameletter FROM stores ORDER BY FirstLetter";
$result = mysql_query($sql);
while($data = mysql_fetch_assoc($result)){
echo $data['name'];
}
--