<?php

include ("error_handler.php");
include ("dbconfig.php");
include ("functions.php");

if (!mysql_connect($dbconfig["server"], $dbconfig["login"], $dbconfig["pass"]) || !mysql_select_db($dbconfig["database"]))
     die ("Erreur m&eacute;canique " . mysql_errno() . " : " . mysql_error());


$r=mysql_query("SELECT DISTINCT c.id_pat FROM consultation c, alctab a WHERE c.id_consult=a.id_consult AND c.consu_type=3 AND a.alc_objectif=1 ORDER BY c.id_pat;");

$smod=array(1=>0,2=>0,3=>0,4=>0,5=>0,6=>0);

while ($c=mysql_fetch_array($r)) {

  $rr=mysql_query("SELECT c.* FROM consultation c, alctab a WHERE c.id_consult=a.id_consult AND c.id_pat='".$c["id_pat"]."' AND c.consu_type=3 AND a.alc_objectif=1 ORDER BY consu_date DESC LIMIT 0,1");
  $cc=mysql_fetch_array($rr);

 
  $rrr=mysql_query("SELECT id_mod FROM situpat WHERE id_consult='".$cc["id_consult"]."'");
  $ccc=mysql_fetch_array($rrr);
  $smod[$ccc["id_mod"]]++;

  if ($ccc["id_mod"]==1)
    echo $cc["id_consult"]."\n";

}

print_r($smod);

?>