"); $dbtot = new FC_SQL ; $log = true ; if ($log) $handle = fopen('log_LoadStatisticheClientiMesi.txt', 'a+') ; $posStart = $_GET['posStart'] ; $count = $_GET['count'] ; if ($log) { fwrite($handle, "posStart = " . $posStart . "\n") ; fwrite($handle, "count = " . $count . "\n") ; } $ordinaper = $_GET["ordinaper"] ; $direction = $_GET["direction"] ; $case = "" ; /*************************************** * controllo la colonna da ordinare ***************************************/ switch($ordinaper) { case 0: // cliente $order_by = "C.Nome $direction, month(O.dataordine)" ; break ; default: // mesi $case = "case when (month(O.dataordine) = $ordinaper) then 1 else 0 end as mese_scelto," ; $order_by = "mese_scelto DESC, num_ord $direction, C.Nome" ; break ; } $arrVal = array() ; $arrId = array() ; $arrCli = array() ; $query = " select C.IdClienti, C.Nome, $case month(O.dataordine) as mese, count(O.idordini) as num_ord from clienti C inner join ordini O on O.idcliente = C.idclienti and O.Anno = $anno group by C.idclienti, C.nome, month(O.dataordine) order by $order_by " ; if ($log) fwrite($handle, "$query \n") ; list($nrowsdati, $dfor) = $db->RecuperaDati($query) ; for ($i=0; $i<$nrowsdati; $i++) { $id = $dfor['IdClienti'][$i] ; $nome = $dfor['Nome'][$i] ; $mese = ($dfor['mese'][$i] != '' ? $dfor['mese'][$i] : 0) ; $num_ord = ($dfor['num_ord'][$i] != '' ? $dfor['num_ord'][$i] : 0) ; if (! array_key_exists($id, $arrId)) { $arrId[$id] = $nome ; $totclienti ++ ; $arrVal[$id]['Nome'] = $nome ; } $arrVal[$id][$mese] = $num_ord ; } if ($log) fwrite($handle, "\n") ; print("") ; @reset($arrVal) ; foreach($arrVal as $is => $arrCli) // while(list($id, $arrCli) = each($arrVal)) { $cliente = htmlspecialchars($arrCli['Nome']) ; if ($log) fwrite($handle, "$cliente\n") ; print ("$cliente") ; for($i=1; $i<=12; $i++) { if ($arrCli[$i] > 0) { $class = "cur_hand" ; $val = $arrCli[$i] ; } else { $class = "" ; $val = 0 ; } print ("$val") ; } print ("") ; } print ("") ; if ($log) fclose($handle) ; ?>