April 5, 2012
Concat SQL Array
Question by oussemos
I want to concat two SQL array in order to have a single JSON result
$sql1=mysql_query("select count(Ip_Routeur) as RouteurDown from Routeurs WHERE Etat_Routeur=0");
$sql2=mysql_query("select count(Ip_Routeur) as RouteurUp from Routeurs WHERE Etat_Routeur=1");
while($row1=mysql_fetch_assoc($sql1))
$output1[]=$row1;
print(json_encode($output1));
while($row2=mysql_fetch_assoc($sql2))
$output2[]=$row2;
print(json_encode($output2));
mysql_close();
Answer by Starx
The codes does not required to combine any array.
You can combine, the two query results with a single query
$sql1=mysql_query("select count(Ip_Routeur) as RouteurDown from Routeurs WHERE Etat_Routeur=0 or Etat_Routeur=1");
$rows = array();
while($row1=mysql_fetch_assoc($sql1)) {
$rows[] = $row1;
}
print(json_encode($rows));
mysql_close();