1
I need to ride a json
as follows:
[
{"SUPERMECADO 1": {"telefones": [ "1999999999","1999999991"]} },
{"SUPERMECADO 2": {"telefones": [ "1999999992","1999999993"]} }
]
But currently my SQL
is returning a array
thus:
[
{"campanha":"SUPERMECADO1","telefone":"1999999999"},
{"campanha":"SUPERMECADO1", telefone":"1999999991"},
{"campanha":"SUPERMECADO2", telefone":"1999999992"},
{"campanha":"SUPERMECADO2", telefone":"1999999993"}
]
my code PHP
:
$query = "SELECT campanha, telefone FROM rest";
$query = mysql_query($query);
$rows = array();
while($r = mysql_fetch_assoc($query)) {
$rows[] = $r;
}
echo json_encode($rows);
How can I build my code PHP
so that I show all phones grouping campaign names?
thank you @Virgilio worked, I will put your answer as correct
– Furlan