How to reduce the number of requests?

Good day to all.

$result = mysql_query("SELECT COUNT(*), sum(q), sum(w), sum(e), sum(r) FROM zakaz WHERE d<'$d' AND c>'$c' AND a='$a' AND z='01'",$db);

I have “a lot” of such requests, with the only difference being z= 01, 02, 03, …. 99. Is there any way to reduce the number of requests?

P.S. Those. not write it in a loop, which is shorter, but reduce the number of requests.


Answer 1, authority 100%

Easiest:

$result = mysql_query("SELECT COUNT(*), sum(q), sum(w), sum(e), sum(r) FROM zakaz WHERE d<'$d' AND c>'$c' AND a='$a' AND z IN ('01','02','03')",$db);
//       z

Added:

   //  
    $z = array('01','02','03');
    //     .
    $out = array();
    //  :
    $query = "SELECT COUNT(*), sum(q) as sum_q, sum(w) as sum_w, sum(e) as sum_e, sum(r) as sum_r FROM zakaz WHERE d<'$d' AND c>'$c' AND a='$a' AND z IN ('".implode("','",$z)."') GROUP BY z";
    //  
    $result = mysql_query($query,$db);
    while ($row=mysql_fetch_assoc($result)) {
    // :
    echo $row['sum_q'];  
    //     
    $out[] = $row;
    //    
    $out[] = $row['sum_q'];
      }

Answer 2

$result = mysql_query("SELECT COUNT(*), sum(q), sum(w), sum(e), sum(r), z FROM zakaz WHERE d<'$d' AND c>'$c' AND a='$a' GROUP BY z",$db);

Now the query will not run in a loop, this loop will be used when reading the results. If you need to somehow limit the z field, then use the condition, say “z BETWEEN ’01’ AND ’99′”