Pb dans une condition d'un requête, PHP/mysql

Résolu
Bonjour,
j'ai un tableau (absenter) qui contient un champs (tot_hr_abs) représentant le nombre d'heurs d'absence d'élèves de mon application pour chaque jour:
absenter(#code_elv,#id_jour,date_abs,tot_hr_abs)

je veux sélectionner la somme des champs "tot_hr_abs" du tableau absenter dans un mois donné;
j'ai essayé avec le code suivant mais, il n'a rien donné:

<?php
//......
$dte_absS=" -".$mois."-".$annee;
$rqT=mysql_query("SELECT SUM(tot_hr_abs) FROM absenter WHERE code_elv='$id_elv' AND date_abs='$dte_absS'");

$tot_hr_absT_S=mysql_fetch_array($rqT);
$tot_h_absS=$tot_hr_absT_S[0];

echo $tot_h_absS;
?>
Veuillez me dire comment résoudre ce pb, et merci d'avance.

9 réponses

  • Votes
  • Date
  • Date décroissante
  1. Un echo de $dte_absS donne bien le meme format?
    Le clcul $dte_absS=" -".$mois."-".$annee; fonctionne bien? il retourne bien le resultat attendu?
    1. nn, ça marche pas, j'ai essayé avec ce code;
      normalement j'ai besoin d'une truc qui représente tous les jours du mois, comme

      for($i=1;$i<31;$i++){
      $dte_absS=$i."-".$moi."-".$ann;}

      ¨_¨ mais dommage ça marche pas aussi.
      1. Bon, le probleme est identidié. C'est votre date.
        Regardez de ce coté: http://www.phptools4u.com/scripts/calendrier/exemples.php
        En intégrant un calendrier a votre page php, vous n'aurez plus ce problème.
        1. merci bcp pour ton aide;
          j'ai intégré le calendrier, mais rien n'est changé
          1. fait un echo de toutes tes variables et donne me les stp.
            Avec la derniere maj de ton code.
            1. voici le code:
              <?php
              ///....
              $id_elv=$_GET['id_elv'];
              $moisJu="06";
              $annee_crtJu=decis_annee($moisJu);

              $dte_absS=" -".$moisJu."-".$annee_crtJu;

              $rqT=mysql_query("SELECT SUM(tot_hr_abs) FROM absenter WHERE code_elv='$id_elv' AND date_abs='$dte_absS'");

              $tot_hr_absT_S=mysql_fetch_array($rqT);
              $tot_h_absS=$tot_hr_absT_S[0];

              if($tot_h_absS=="") { $tot_h_absS="?"; }

              echo "annee_crtJu: ".$annee_crtJu."<br>";
              echo "date_absS: ".$dte_absS."<br>";
              echo "rqT: ".$rqT."<br>";
              echo "tot_hr_absT_S: ".$tot_hr_absT_S."<br>";
              echo "tot_h_absS: ".$tot_h_absS;

              mysql_close();
              ?>

              et voici le résultat:

              annee_crtJu: 2011
              date_absS: -06-2011
              rqT: Resource id #6
              tot_hr_absT_S: Array
              tot_h_absS ?
              1. j'ai trouvé la solution, voilà:

                <?php
                ///....
                $id_elv=$_GET['id_elv'];
                $moisJu="06";
                $annee_crtJu=decis_annee($moisJu);

                $tab=array();

                for($i=1;$i<=30;$i++){
                $dte_absS=$i."-".$moisJu."-".$annee_crtJu;


                $rqT=mysql_query("SELECT SUM(tot_hr_abs) FROM absenter WHERE code_elv='$id_elv' AND date_abs='$dte_absS'");

                $tot_hr_absT_S=mysql_fetch_array($rqT);
                $tot_h_absS=$tot_hr_absT_S[0];

                if($tot_h_absS=="") { $tot_h_absS="?"; }
                else { $tab[$i-1]=$tot_h_absS;}

                }

                $somm=0;
                foreach($tab as $val)
                {
                $somm+=$val;
                }
                echo $somm;


                mysql_close();
                ?>

                et merci bcp Super_carotte.