0
How to use ORDER BY for a data that does not come from db? ex:
$query = $mysql->query("SELECT * FROM db_aux ;");
while($row = $query->fetch_array())
{
$url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=";
$url .= $row['cep_local']."&destinations=".$row['cep_user'];
$url .= "&language=pt&mode=car&key=AIzaSyDL6_dJ-Mbi_03_g6lHhWibxY22Z2UeYZQ";
$json = file_get_contents($url);
$json_data = json_decode($json, true);
}
I want to order by this data that comes from the consultation json
, DESC
$json_data['rows'][0]['elements'][0]['distance']['text'];
in his
$json_data
has several lines? as would be an example of the$json_data
???– novic
https://maps.googleapis.com/maps/api/distancematrix/json?origins=86830-000&destinations=86015-810&language=pt&mode=car&key=AIzaSyDL6_dJ-Mbi_03_g6lHhWibxY22Z2UeYZQ
– João Pedro Morais
{ "destination_addresses" : [ "Nova Londres, Londrina - PR, 86015-810, Brasil" ], "origin_addresses" : [ "Rio Bom - PR, 86830-000, Brasil" ], "Rows" : [ { "Elements" [ { "Distance" { "text" "111 km", "value" 111283 }, "Duration" { "text" : "1 hour 58 min.", "value" : 7101 }, "status" "OK" } ] } ], "status" "OK" }
– João Pedro Morais
In case it is an item you want to order?
– novic
I want to order by distance
– João Pedro Morais
In the example case if you have a
$json_data['rows'][0]['elements'][0]['distance']['text']
my question is? how many items have these because an item does not need to be ordered!? correct– novic
Yes he gives o while and comes all bank ceps in case some 50, I want to order from minor to major
– João Pedro Morais
because your code isn’t wrong? shouldn’t it be on the last line
$json_data[] = json_decode($json, true);
???– novic
it’s working normal just doesn’t order
– João Pedro Morais
Have you seen the API documentation to see if there is no parameter you can pass in the query that returns already ordered data? Making this type of customer-side operation is quite costly at the performance level.
– Tiago Leite
@Joãopedromorais in the ultma line doesn’t have to be a
array
?– novic
No poblema, will be used on a panel, not directly to the customer
– João Pedro Morais
I do not understand very well of json but always use as this there, only that I never needed to order or receive more than 1 dice
– João Pedro Morais