I have "channels" in my Android application being represented by an integer in a MySQL db on my server. Basically there are five zones in the application each with five sub channels. The "zones" increment the integer by multiples of 1 while the sub channels increment by 100. (i.e. zone 1, sub-channel 3 equates to int "300") (i.e. zone 3, sub-channel 3 equates to int "303") Okay so this php returns an array[5] with the total number of users in each zone. How can I make this script more efficient? It works but it takes time.
<?php
ini_set('display_errors',1);
$json=$_POST['user'];
$json=str_replace('\\','',$json);
$user=json_decode($json);
$pdo=new PDO('mysql://hostname=localhost;dbname=database', 'user', 'password');
$channels=array(100,200,300,400,500);
$full_status=array();
$current_status=array();
for($i=0;$i<5;$i++){
for($j=0;$j<5;$j++){
$total=$pdo->query("SELECT count(user_id) AS count FROM accounts WHERE channel!='0' AND channel='{$channels[$j]}'");
$total=$total->fetchAll(PDO::FETCH_ASSOC);
$total=$total[0]['count'];
$current_status[$j]=$total;
$channels[$j]++;
}
$full_status[]=array_sum($current_status);
}
echo json_encode(array("data"=>$full_status));
?>