0) $where_agenti = "O.idagente = $id_agente" ; if ($id_cliente > 0) $where_clienti = "O.idcliente = $id_cliente" ; // componi la query opportuna switch ($item) { case 'agenti': switch ($params['combo']) { case 'cliente': $ql = " select distinct C.IdClienti as Id, C.Nome as Nome from ordini O inner join clienti C on C.idclienti = O.idcliente where O.Anno = $anno and $where_agenti and O.idpagamento = 1 and (O.NumAssegno <= '0' or O.NumAssegno is null) order by C.nome " ; break ; case 'fornitore': $ql = " select distinct F.IdFornitori as Id, F.Nome as Nome from ordini O inner join fornitori F on F.idfornitori = O.idfornitore where O.Anno = $anno and $where_agenti and O.idpagamento = 1 and (O.NumAssegno <= '0' or O.NumAssegno is null) order by F.nome " ; break ; } break ; case 'clienti': $ql = " select distinct F.IdFornitori as Id, F.Nome as Nome from ordini O inner join fornitori F on F.idfornitori = O.idfornitore where O.Anno = $anno and $where_agenti and $where_clienti and O.idpagamento = 1 and (O.NumAssegno <= '0' or O.NumAssegno is null) order by F.nome " ; break ; break ; } if ($log) { fwrite($handle, "QUERY = " . $ql . "\n") ; } $str_res = '' ; list($nl, $dl) = $db->RecuperaDati($ql) ; for ($i = 0; $i < $nl; $i++ ) $str_res .= $dl["Id"][$i] . '^' . $dl["Nome"][$i] . ';' ; // ritorna il risultato echo $str_res ; if ($log) fclose($handle) ; ?>