cheeseus

Statistics All - Single Query

May 16th, 2014
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. <?php
  2. // statistics.php
  3.  
  4. $client_list = "";
  5.  
  6. $years = array("2010", "2011", "2012", "2013", "2014");
  7.  
  8. foreach($years as $year) {
  9.    
  10.     $stats[$year] = $db->getAll("SELECT clientname, type, currency, unit,
  11.                 COUNT(projectID) as count,
  12.                 SUM(units) AS units_sum,
  13.                 SUM(totalprice) AS client_sum
  14.                 FROM `".PROJECT_TABLE."`
  15.                 WHERE YEAR(duedate) = {$year}
  16.                 GROUP BY clientID, type, unit, currency");
  17.     }
  18.  
  19. //print_r($stat_by_type);
  20.  
  21. foreach($stats as $type_key => $type_value) {
  22.    
  23.     $client_list .= "<tr><td>".$type_key."</td></tr><tr><td>";
  24.    
  25.     print "<pre>";
  26.     print_r($type_value);
  27.     print "</pre>";
  28.    
  29.     foreach($type_value as $value) {
  30.         $client_list .= $value->clientname.":";
  31.         $client_list .= "<li>".$value->count." ".$value->type."</li>";
  32.         $client_list .= "<li>".$value->units_sum." ".$value->unit."</li>";
  33.         $client_list .= "<li>".$value->client_sum." ".$value->currency."</li>";
  34.     }
  35.     $client_list .= "</td></tr>";
  36. }
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment