php - Looping through A-Z and sorting array to JSON using MYSQL -
arrays json... enemy.
i'm trying sort a-z properly, explain. have following php code:
$az_result = $con->query("select * games order game_title"); while($az_row = mysqli_fetch_array($az_result)) { $the_az_game_data = array(); $empty_letter = ''; $current_letter = strtolower($az_row['game_title'][0]); if ($empty_letter != $current_letter) { $cur_letter = strtoupper($current_letter); $empty_letter = $current_letter; } $game_id = $az_row['id']; $the_az_game_data['game_id'] = $game_id; $the_az_game_data['game_name'] = $az_row['game_title']; $the_az_game_data['game_link'] = $az_row['game_link']; //store data $az_data[$cur_letter] = $the_az_game_data; } $game_data[] = $az_data; echo '{"games":'.json_encode($game_data, json_unescaped_slashes | json_pretty_print).'}'; the following json output:
{"games":[ { "c": { "game_id": "17", "game_name": "cool game", "game_link": "cool-game", }, "r": { "game_id": "2", "game_name": "rad game 2", "game_link": "rad-game-2", }, "t": { "game_id": "1", "game_name": "test game", "game_link": "test-game", } } ]} so have it, what's wrong there multiple games in letters. overriding arrays or something? can explain, thanks!
Comments
Post a Comment