[RESOLU] Lancer une requête sql avec boite à cocher

Eléphant du PHP | 134 Messages

22 sept. 2013, 13:06

Re

Justement il est pas dans mon while , seulement mon input :
 <td width="1%"><input name="champ[]" type="checkbox" value="<?php echo $datas["id"]; ?>"/><?php echo $datas["id"]; ?></td>

Remis mon code complet et j'ai refait un deuxième while à la fin , mais franchement la je suis paumé.
<?php
//------------------------------------------------------------------------ GESTION DES ETAT DES PRETS MATERIELS - ACTION 11 ---------------------------------------------//		
		
	if($_GET['action'] == 11 ){  /// ACTION 11 - GESTION DES ETAT DES PRETS MATERIELS - //
		
    echo '<h3 class="tit">Messages Systèmes</h3>
  
         <p class="msg done">Vous êtes sur les Etats des Prêts Matériels</p>'; 
        
   
  $db = mysql_connect('localhost', '**', '********);
  mysql_select_db('michelte_Gestion_Materiels', $db);
  mysql_query("SET NAMES UTF8"); 
   $sql = "SELECT *,DATE_FORMAT(date_affiche, '%d/%m/%Y %Hh:%i' ) AS 'datef',DATE_FORMAT(date_sortie, '%d/%m/%Y' ) AS 'date_de_sortie'  FROM materiels3 WHERE disponibilite >= 2   ORDER BY designation";  // ON RECHERCHE LE MATERIEL EN DISPONIBILITE = 2 DONC SUR CHANTIER //
  $datedujour =  date('Y/m/d') ;

   
  $req = mysql_query($sql) or die (mysql_error());
  mysql_query("SET NAMES UTF8"); 
  mysql_query("'encoding' => 'utf8'"); 

  echo '<table width="100%" border="1" cellspacing="0" cellpadding="0" id="menuTable" class="display">';


  echo '<thead><tr>';
  echo '<th style="color:#046380;text-align:center;"><strong>Mise à jour</strong>  
  </th>
  
 <th style="color:#046380; text-align:center;">Designation du Matériel</th>
 <th style="color:#046380; text-align:center;">Identification</th>
 <th style="color:#046380; text-align:center;">Etat</th>
 <th style="color:#046380; text-align:center;">Disponibilité</th>
 <th style="color:#046380; text-align:center;">Attribution</th>
 <th style="color:#B9121B; text-align:center;">Chantier</th>
 <th style="color:#B9121B; text-align:center;">Date de Sortie</th>
 <th style="color:#B9121B; text-align:center;">Prêt/J</th>
 <th style="color:#B9121B; text-align:center;">Action</th>
 <th style="color:#B9121B; text-align:center;">Cocher</th>
 </tr></thead>';
  
  
  
  
  echo '<tbody>';
  while ($datas = mysql_fetch_assoc($req)) {
  mysql_query("SET NAMES UTF8"); 
  mysql_query("'encoding' => 'utf8'"); 	  
  echo '<tr>';
  ?>
  
  
  
 <td width="9%" class="rouge" id="datef-<?php echo $datas['id']; ?>" ondblclick="enregistre_controle(<?php echo $datas['id']; ?>, this, 'datef', 'texte')">
  <?php echo $datas['datef']?></td>

<td class="noir" id="designation-<?php echo $datas['id']; ?>" ondblclick="enregistre_controle(<?php echo $datas['id']; ?>, this, 'designation', 'texte')">
  <?php echo $datas['designation']?></td>
  
<td class="vert" id="reference-<?php echo $datas['id']; ?>" ondblclick="enregistre_controle(<?php echo $datas['id']; ?>, this, 'reference', 'texte')">
 <?php echo $datas['reference']?></td>
  
<td class="vert">


 <?php

   if( $datas['etat'] == 0  ) // CONFORME //
  
     {  echo '<img name="ok" src="png/ok.png" width="40" height="40" alt="" /> </td>'; 
 
     } 
	 
	 if( $datas['etat'] == 1  ) {  //   NON CONFORME //
   

      echo '<img name="ok" src="png/attention1.png" width="40" height="40" alt="" /></td>';
	
	         }
			 
	 if( $datas['etat'] == 5  ) {  // CONTROLE A - 30 JOURS  //
   

      echo '<img name="ok" src="png/J30.png" width="40" height="40" alt="" /></td>';
	
	         }	 
			 
	 	 
	 if( $datas['etat'] == 3  ) {  // HORS SERVICE  //
   

      echo '<img name="ok" src="png/hors_service.png" width="40" height="40" alt="" /></td>';
	
	         }	
			 
	 if( $datas['etat'] == 2  ) {  // EN REPARATION //
   

      echo '<img name="ok" src="png/reparation (1).png" width="50" height="50" alt="" /></td>';
	
	         }		 
			 	 
			 
?> 

  
  <?php //  if( $datas['disponibilite'] ==2)  {  // PRET INFERIEUR A 60 JOURS TEXTE NOIR   //  ?>
   
            <td class="vert" id="disponibilite-<?php echo $datas['id']; ?>" ondblclick="enregistre_controle(<?php echo $datas['id']; ?>, this, 'disponibilite', 'texte')">
  <?php echo $datas['disponibilite']?></td>
  	                          
                              <?php  //}   // FERME CONDITION ?>
                               
     <?php // if( $datas['disponibilite'] ==3) {  // PRET SUPERIEUR A 60 JOURS TEXTE ROUGE   //  ?>
   
               
                               
							   <?php //  }  // FERME CONDITION ?> 
  

<td width="8%" class="noir" id="nom_retrait-<?php echo $datas['id']; ?>" ondblclick="enregistre_controle(<?php echo $datas['id']; ?>, this, 'nom_retrait', 'texte')">
  <?php echo $datas['nom_retrait']?></td>
  
<td class="noir" id="chantier-<?php echo $datas['id']; ?>" ondblclick="enregistre_controle(<?php echo $datas['id']; ?>, this, 'chantier', 'texte')">
  <?php echo $datas['chantier']?></td> 

<td class="vert" id="date_sortie-<?php echo $datas['id']; ?>" ondblclick="enregistre_controle(<?php echo $datas['id']; ?>, this, 'date_sortie', 'texte')">
  <?php echo $datas['date_de_sortie']?></td> 
  
  
  
   <?php  
   
   
	$date_pret = $datas['date_sortie']; // Date de sortie format français  >> 00/00/0000 //
    // $date_sortie = date('Y-m-d', strtotime($date_pret)); // On met la date au format anglais pour calcul //
	$datedujour =  date('Y-m-d') ;  // Date du jour //
    
    $nbjours = floor((strtotime($datedujour) - strtotime($date_pret)+60*60*1)/(60*60*24));
    $dispo = $datas['disponibilite'];
	if ($dispo = '0' ){
	$id = $datas['id'];
	mysql_query("UPDATE materiels3 SET date_sortie='0000-00-00 00:00:00' WHERE id='$id' LIMIT 1");
	} 
	
?>

 	 
	<?php if( $nbjours < 60  )  {  // PRET INFERIEUR A 60 JOURS TEXTE NOIR   //  ?>
   
               <td class="noir"><center><?php echo $nbjours; ?></td>	
	                          
                              <?php }   // FERME CONDITION ?>
                               
     <?php if( $nbjours > 60  ) {  // PRET SUPERIEUR A 60 JOURS TEXTE ROUGE   //  ?>
   
               <td class="rouge"><center><?php echo $nbjours; ?></td>	
	                          
                               <?php }  // FERME CONDITION ?>                          
  
<td width="6%" class="noir">   
<a href="javascript:BRB_PHP_DelWithCon('Ajout_Materiels/sortie.php','id',<?php echo $datas['id']; ?>,'Vous allez modifier une fiche Matériels ? ');"><img name="supprimer" src="images/fleche10.png" width="20" height="20" alt="" /></a>

<a href="javascript:BRB_PHP_DelWithCon('Fonction_php/pointage-retour2.php','id',<?php echo $datas['id']; ?>,'Voulez-vous saisir le pointage du retour de ce Matériel ? ');"><img name="Retour Matériels" src="images/retour.png" width="20" height="20" alt="" /></a>

<a href="javascript:BRB_PHP_DelWithCon('Fonction_php/Supprimer2.php','id',<?php echo $datas['id']; ?>,'Êtes-vous sûr de vouloir supprimer la fiche Matériel ? ');"><img name="supprimer" src="images/file_delete.png" width="17" height="17" alt="" /></a>

</td>

<?php
/* ------------------ CASE A COCHER ------------------ */
 
    if (isset($_POST['champ'])) {
   
	for ($i=0;$i<sizeof($_POST['champ']);$i++) {
 
	$champ[$i] = $_POST['champ'][$i];
	$numero_materiel = $_POST['champ'][$i];
 
	$query2 = mysql_query("SELECT * materiels3  WHERE Id = '$numero_materiel'");
	$result_donnees2=mysql_fetch_assoc($query2);
    
	//"UPDATE materiels3 SET disponibilite='',chantier='',nom_retrait='',date_sortie='' WHERE id IN (".$id.")";
	$query ="UPDATE materiels3 SET disponibilite='',chantier='',nom_retrait='',date_sortie='' WHERE id = '.$champ[$i].'";
	$result = mysql_query($query)  or die('Erreur SQL ! '.$query.'<br/>'.mysql_error());
    
	//$query = 'DELETE FROM minichat WHERE id = '. $champ[$i];
	
 
 
    }
  }
 
 
?>

	 
 <td width="1%"><input name="champ[]" type="checkbox" value="<?php echo $datas["id"]; ?>"/><?php echo $datas["id"]; ?></td>
 
 
<?php
  echo '</tr>';
  }
  
  echo '';
  echo '</tbody><tfoot><tr><th colspan="12">&nbsp;</th></tr></tfoot>';
  
    
  
  echo '</table>';
  echo'<form>';
 
 
 echo '<form action="accueil.php?action=11" method="POST">';
while ($datas = mysql_fetch_assoc($req)) 
{
   echo'<input name="champ[]" type="checkbox" value="<?php echo $datas["id"]; ?>"/><?php echo $datas["id"]; ?>';
    // affichage de tes données => une itération pour une ligne donc
}
?>
<input type="submit"></form>

  
 <?php 
  
  mysql_free_result($req);
  mysql_close();
  
 }  // ON FERME GESTION DES ETATS DES PRETS MATERIELS - ACTION 11 //
?>  



ViPHP
xTG
ViPHP | 7331 Messages

22 sept. 2013, 14:51

Je vois une balise de fermeture de form mais pas son ouverture.
Toujours est-il que pour debugguer et comprendre ce qui se passe tu peux afficher la variable $_POST après avoir coché plusieurs cases et soumis le formulaire.

Eléphant du PHP | 134 Messages

22 sept. 2013, 15:06

Re

Ce code ne fonctionne que pour une ligne , j'ai essayé de mettre l'ouverture du form et fermeture a plusieurs endroits mais rien.

Ou je dois mettre >> <form action="accueil.php?action=11" method="post">
et la fermeture >><input name="OK" type="submit" /></form>
pour cela je redonne mon code complet avec le tableau ( deuxième partie php )


<td width="1%" class="noir">
 <?php
 
 echo '<form action="accueil.php?action=11" method="post">';
 echo '<input type="checkbox" name="check[]"  value="'. $datas['id'].' "/>';
 $id =$datas['id'];
if (isset($_POST['check'])) {
    $id = implode(',', $_POST['check']);
    $sql = "UPDATE materiels3 SET disponibilite='',chantier='',nom_retrait='',date_sortie='' WHERE id IN (".$id.")";
   $result=mysql_query($sql);

//en cas d'échec de la mise à jour, on affiche le message d'erreur
  if (!$result) {
   echo "erreur sql liée  à la mise à jour:\n" ;
    die( mysql_error());
}
 }
 echo '<input name="OK" type="submit" /></form>';
?>

</td>


Deuxième partie

<?php
//------------------------------------------------------------------------ GESTION DES ETAT DES PRETS MATERIELS - ACTION 11 ---------------------------------------------//		
		
	if($_GET['action'] == 11 ){  /// ACTION 11 - GESTION DES ETAT DES PRETS MATERIELS - //
		
    echo '<h3 class="tit">Messages Systèmes</h3>
  
         <p class="msg done">Vous êtes sur les Etats des Prêts Matériels</p>'; 
        
   
  $db = mysql_connect('localhost', '***, ****');
  mysql_select_db('michelte_Gestion_Materiels', $db);
  mysql_query("SET NAMES UTF8"); 
   $sql = "SELECT *,DATE_FORMAT(date_affiche, '%d/%m/%Y %Hh:%i' ) AS 'datef',DATE_FORMAT(date_sortie, '%d/%m/%Y' ) AS 'date_de_sortie'  FROM materiels3 WHERE disponibilite >= 2   ORDER BY designation";  // ON RECHERCHE LE MATERIEL EN DISPONIBILITE = 2 DONC SUR CHANTIER //
  $datedujour =  date('Y/m/d') ;

   
  $req = mysql_query($sql) or die (mysql_error());
  mysql_query("SET NAMES UTF8"); 
  mysql_query("'encoding' => 'utf8'"); 

  echo '<table width="100%" border="1" cellspacing="0" cellpadding="0" id="menuTable" class="display">';


  echo '<thead><tr>';
  echo '<th style="color:#046380;text-align:center;"><strong>Mise à jour</strong>  
  </th>
  
 <th style="color:#046380; text-align:center;">Designation du Matériel</th>
 <th style="color:#046380; text-align:center;">Identification</th>
 <th style="color:#046380; text-align:center;">Etat</th>
 <th style="color:#046380; text-align:center;">Disponibilité</th>
 <th style="color:#046380; text-align:center;">Attribution</th>
 <th style="color:#B9121B; text-align:center;">Chantier</th>
 <th style="color:#B9121B; text-align:center;">Date de Sortie</th>
 <th style="color:#B9121B; text-align:center;">Prêt/J</th>
 <th style="color:#B9121B; text-align:center;">Action</th>
 <th style="color:#B9121B; text-align:center;">Cocher</th>
 </tr></thead>';
  
  
  
  
  echo '<tbody>';
  while ($datas = mysql_fetch_assoc($req)) {
  mysql_query("SET NAMES UTF8"); 
  mysql_query("'encoding' => 'utf8'"); 	  
  echo '<tr>';
  ?>
  
  
  
 <td width="9%" class="rouge" id="datef-<?php echo $datas['id']; ?>" ondblclick="enregistre_controle(<?php echo $datas['id']; ?>, this, 'datef', 'texte')">
  <?php echo $datas['datef']?></td>

<td class="noir" id="designation-<?php echo $datas['id']; ?>" ondblclick="enregistre_controle(<?php echo $datas['id']; ?>, this, 'designation', 'texte')">
  <?php echo $datas['designation']?></td>
  
<td class="vert" id="reference-<?php echo $datas['id']; ?>" ondblclick="enregistre_controle(<?php echo $datas['id']; ?>, this, 'reference', 'texte')">
 <?php echo $datas['reference']?></td>
  
<td class="vert">


 <?php

   if( $datas['etat'] == 0  ) // CONFORME //
  
     {  echo '<img name="ok" src="png/ok.png" width="40" height="40" alt="" /> </td>'; 
 
     } 
	 
	 if( $datas['etat'] == 1  ) {  //   NON CONFORME //
   

      echo '<img name="ok" src="png/attention1.png" width="40" height="40" alt="" /></td>';
	
	         }
			 
	 if( $datas['etat'] == 5  ) {  // CONTROLE A - 30 JOURS  //
   

      echo '<img name="ok" src="png/J30.png" width="40" height="40" alt="" /></td>';
	
	         }	 
			 
	 	 
	 if( $datas['etat'] == 3  ) {  // HORS SERVICE  //
   

      echo '<img name="ok" src="png/hors_service.png" width="40" height="40" alt="" /></td>';
	
	         }	
			 
	 if( $datas['etat'] == 2  ) {  // EN REPARATION //
   

      echo '<img name="ok" src="png/reparation (1).png" width="50" height="50" alt="" /></td>';
	
	         }		 
			 	 
			 
?> 

  
  <?php //  if( $datas['disponibilite'] ==2)  {  // PRET INFERIEUR A 60 JOURS TEXTE NOIR   //  ?>
   
            <td class="vert" id="disponibilite-<?php echo $datas['id']; ?>" ondblclick="enregistre_controle(<?php echo $datas['id']; ?>, this, 'disponibilite', 'texte')">
  <?php echo $datas['disponibilite']?></td>
  	                          
                              <?php  //}   // FERME CONDITION ?>
                               
     <?php // if( $datas['disponibilite'] ==3) {  // PRET SUPERIEUR A 60 JOURS TEXTE ROUGE   //  ?>
   
               
                               
							   <?php //  }  // FERME CONDITION ?> 
  

<td width="8%" class="noir" id="nom_retrait-<?php echo $datas['id']; ?>" ondblclick="enregistre_controle(<?php echo $datas['id']; ?>, this, 'nom_retrait', 'texte')">
  <?php echo $datas['nom_retrait']?></td>
  
<td class="noir" id="chantier-<?php echo $datas['id']; ?>" ondblclick="enregistre_controle(<?php echo $datas['id']; ?>, this, 'chantier', 'texte')">
  <?php echo $datas['chantier']?></td> 

<td class="vert" id="date_sortie-<?php echo $datas['id']; ?>" ondblclick="enregistre_controle(<?php echo $datas['id']; ?>, this, 'date_sortie', 'texte')">
  <?php echo $datas['date_de_sortie']?></td> 
  
  
  
   <?php  
   
   
	$date_pret = $datas['date_sortie']; // Date de sortie format français  >> 00/00/0000 //
    // $date_sortie = date('Y-m-d', strtotime($date_pret)); // On met la date au format anglais pour calcul //
	$datedujour =  date('Y-m-d') ;  // Date du jour //
    
    $nbjours = floor((strtotime($datedujour) - strtotime($date_pret)+60*60*1)/(60*60*24));
    $dispo = $datas['disponibilite'];
	if ($dispo = '0' ){
	$id = $datas['id'];
	mysql_query("UPDATE materiels3 SET date_sortie='0000-00-00 00:00:00' WHERE id='$id' LIMIT 1");
	} 
	
?>

 	 
	<?php if( $nbjours < 60  )  {  // PRET INFERIEUR A 60 JOURS TEXTE NOIR   //  ?>
   
               <td class="noir"><center><?php echo $nbjours; ?></td>	
	                          
                              <?php }   // FERME CONDITION ?>
                               
     <?php if( $nbjours > 60  ) {  // PRET SUPERIEUR A 60 JOURS TEXTE ROUGE   //  ?>
   
               <td class="rouge"><center><?php echo $nbjours; ?></td>	
	                          
                               <?php }  // FERME CONDITION ?>                          
  
<td width="6%" class="noir">   
<a href="javascript:BRB_PHP_DelWithCon('Ajout_Materiels/sortie.php','id',<?php echo $datas['id']; ?>,'Vous allez modifier une fiche Matériels ? ');"><img name="supprimer" src="images/fleche10.png" width="20" height="20" alt="" /></a>

<a href="javascript:BRB_PHP_DelWithCon('Fonction_php/pointage-retour2.php','id',<?php echo $datas['id']; ?>,'Voulez-vous saisir le pointage du retour de ce Matériel ? ');"><img name="Retour Matériels" src="images/retour.png" width="20" height="20" alt="" /></a>

<a href="javascript:BRB_PHP_DelWithCon('Fonction_php/Supprimer2.php','id',<?php echo $datas['id']; ?>,'Êtes-vous sûr de vouloir supprimer la fiche Matériel ? ');"><img name="supprimer" src="images/file_delete.png" width="17" height="17" alt="" /></a>

</td>
<td width="1%" class="noir">
 <?php
 
 echo '<form action="accueil.php?action=11" method="post">';
 echo '<input type="checkbox" name="check[]"  value="'. $datas['id'].' "/>';
 $id =$datas['id'];
if (isset($_POST['check'])) {
    $id = implode(',', $_POST['check']);
    $sql = "UPDATE materiels3 SET disponibilite='',chantier='',nom_retrait='',date_sortie='' WHERE id IN (".$id.")";
   $result=mysql_query($sql);

//en cas d'échec de la mise à jour, on affiche le message d'erreur
  if (!$result) {
   echo "erreur sql liée  à la mise à jour:\n" ;
    die( mysql_error());
}
 }
 echo '<input name="OK" type="submit" /></form>';
?>

</td>
<?php
  echo '</tr>';
  }
  echo '</tbody>';
  echo '<tfoot><tr><th colspan="12">&nbsp;</th></tr></tfoot>';
  echo '</table>';
  mysql_free_result($req);
  mysql_close();
  
 }  // ON FERME GESTION DES ETATS DES PRETS MATERIELS - ACTION 11 //
?>  


Mammouth du PHP | 571 Messages

22 sept. 2013, 15:21

la balise d'ouverture de form(<form...>) est à mettre avant le while, le bouton submit et balise de fermerture de form(</form>) seront placés après le while:
<?php
//------------------------------------------------------------------------ GESTION DES ETAT DES PRETS MATERIELS - ACTION 11 ---------------------------------------------//            
               
        if($_GET['action'] == 11 ){  /// ACTION 11 - GESTION DES ETAT DES PRETS MATERIELS - //
               
    echo '<h3 class="tit">Messages Systèmes</h3>
 
         <p class="msg done">Vous êtes sur les Etats des Prêts Matériels</p>';
       
   
  $db = mysql_connect('localhost', '***, ****');
  mysql_select_db('michelte_Gestion_Materiels', $db);
  mysql_query("SET NAMES UTF8");
   $sql = "SELECT *,DATE_FORMAT(date_affiche, '%d/%m/%Y %Hh:%i' ) AS 'datef',DATE_FORMAT(date_sortie, '%d/%m/%Y' ) AS 'date_de_sortie'  FROM materiels3 WHERE disponibilite >= 2   ORDER BY designation";  // ON RECHERCHE LE MATERIEL EN DISPONIBILITE = 2 DONC SUR CHANTIER //
  $datedujour =  date('Y/m/d') ;

   
  $req = mysql_query($sql) or die (mysql_error());
  mysql_query("SET NAMES UTF8");
  mysql_query("'encoding' => 'utf8'");

  echo '<table width="100%" border="1" cellspacing="0" cellpadding="0" id="menuTable" class="display">';


  echo '<thead><tr>';
  echo '<th style="color:#046380;text-align:center;"><strong>Mise à jour</strong>  
  </th>
 
 <th style="color:#046380; text-align:center;">Designation du Matériel</th>
 <th style="color:#046380; text-align:center;">Identification</th>
 <th style="color:#046380; text-align:center;">Etat</th>
 <th style="color:#046380; text-align:center;">Disponibilité</th>
 <th style="color:#046380; text-align:center;">Attribution</th>
 <th style="color:#B9121B; text-align:center;">Chantier</th>
 <th style="color:#B9121B; text-align:center;">Date de Sortie</th>
 <th style="color:#B9121B; text-align:center;">Prêt/J</th>
 <th style="color:#B9121B; text-align:center;">Action</th>
 <th style="color:#B9121B; text-align:center;">Cocher</th>
 </tr></thead>';
 
 
 
 
  echo '<tbody>';
echo '<form action="accueil.php?action=11" method="post">'; //ouverture du form
  while ($datas = mysql_fetch_assoc($req)) {
  mysql_query("SET NAMES UTF8");
  mysql_query("'encoding' => 'utf8'");    
  echo '<tr>';
  ?>
 
 
 
 <td width="9%" class="rouge" id="datef-<?php echo $datas['id']; ?>" ondblclick="enregistre_controle(<?php echo $datas['id']; ?>, this, 'datef', 'texte')">
  <?php echo $datas['datef']?></td>

<td class="noir" id="designation-<?php echo $datas['id']; ?>" ondblclick="enregistre_controle(<?php echo $datas['id']; ?>, this, 'designation', 'texte')">
  <?php echo $datas['designation']?></td>
 
<td class="vert" id="reference-<?php echo $datas['id']; ?>" ondblclick="enregistre_controle(<?php echo $datas['id']; ?>, this, 'reference', 'texte')">
 <?php echo $datas['reference']?></td>
 
<td class="vert">


 <?php

   if( $datas['etat'] == 0  ) // CONFORME //
 
     {  echo '<img name="ok" src="png/ok.png" width="40" height="40" alt="" /> </td>';
 
     }
         
         if( $datas['etat'] == 1  ) {  //   NON CONFORME //
   

      echo '<img name="ok" src="png/attention1.png" width="40" height="40" alt="" /></td>';
       
                 }
                         
         if( $datas['etat'] == 5  ) {  // CONTROLE A - 30 JOURS  //
   

      echo '<img name="ok" src="png/J30.png" width="40" height="40" alt="" /></td>';
       
                 }       
                         
                 
         if( $datas['etat'] == 3  ) {  // HORS SERVICE  //
   

      echo '<img name="ok" src="png/hors_service.png" width="40" height="40" alt="" /></td>';
       
                 }     
                         
         if( $datas['etat'] == 2  ) {  // EN REPARATION //
   

      echo '<img name="ok" src="png/reparation (1).png" width="50" height="50" alt="" /></td>';
       
                 }               
                                 
                         
?>

 
  <?php //  if( $datas['disponibilite'] ==2)  {  // PRET INFERIEUR A 60 JOURS TEXTE NOIR   //  ?>
   
            <td class="vert" id="disponibilite-<?php echo $datas['id']; ?>" ondblclick="enregistre_controle(<?php echo $datas['id']; ?>, this, 'disponibilite', 'texte')">
  <?php echo $datas['disponibilite']?></td>
                                 
                              <?php  //}   // FERME CONDITION ?>
                               
     <?php // if( $datas['disponibilite'] ==3) {  // PRET SUPERIEUR A 60 JOURS TEXTE ROUGE   //  ?>
   
               
                               
                                                           <?php //  }  // FERME CONDITION ?>
 

<td width="8%" class="noir" id="nom_retrait-<?php echo $datas['id']; ?>" ondblclick="enregistre_controle(<?php echo $datas['id']; ?>, this, 'nom_retrait', 'texte')">
  <?php echo $datas['nom_retrait']?></td>
 
<td class="noir" id="chantier-<?php echo $datas['id']; ?>" ondblclick="enregistre_controle(<?php echo $datas['id']; ?>, this, 'chantier', 'texte')">
  <?php echo $datas['chantier']?></td>

<td class="vert" id="date_sortie-<?php echo $datas['id']; ?>" ondblclick="enregistre_controle(<?php echo $datas['id']; ?>, this, 'date_sortie', 'texte')">
  <?php echo $datas['date_de_sortie']?></td>
 
 
 
   <?php  
   
   
        $date_pret = $datas['date_sortie']; // Date de sortie format français  >> 00/00/0000 //
    // $date_sortie = date('Y-m-d', strtotime($date_pret)); // On met la date au format anglais pour calcul //
        $datedujour =  date('Y-m-d') ;  // Date du jour //
   
    $nbjours = floor((strtotime($datedujour) - strtotime($date_pret)+60*60*1)/(60*60*24));
    $dispo = $datas['disponibilite'];
        if ($dispo = '0' ){
        $id = $datas['id'];
        mysql_query("UPDATE materiels3 SET date_sortie='0000-00-00 00:00:00' WHERE id='$id' LIMIT 1");
        }
       
?>

         
        <?php if( $nbjours < 60  )  {  // PRET INFERIEUR A 60 JOURS TEXTE NOIR   //  ?>
   
               <td class="noir"><center><?php echo $nbjours; ?></td>   
                                 
                              <?php }   // FERME CONDITION ?>
                               
     <?php if( $nbjours > 60  ) {  // PRET SUPERIEUR A 60 JOURS TEXTE ROUGE   //  ?>
   
               <td class="rouge"><center><?php echo $nbjours; ?></td>  
                                 
                               <?php }  // FERME CONDITION ?>                          
 
<td width="6%" class="noir">  
<a href="javascript&#058;BRB_PHP_DelWithCon('Ajout_Materiels/sortie.php','id',<?php echo $datas['id']; ?>,'Vous allez modifier une fiche Matériels ? ');"><img name="supprimer" src="images/fleche10.png" width="20" height="20" alt="" /></a>

<a href="javascript&#058;BRB_PHP_DelWithCon('Fonction_php/pointage-retour2.php','id',<?php echo $datas['id']; ?>,'Voulez-vous saisir le pointage du retour de ce Matériel ? ');"><img name="Retour Matériels" src="images/retour.png" width="20" height="20" alt="" /></a>

<a href="javascript&#058;BRB_PHP_DelWithCon('Fonction_php/Supprimer2.php','id',<?php echo $datas['id']; ?>,'Êtes-vous sûr de vouloir supprimer la fiche Matériel ? ');"><img name="supprimer" src="images/file_delete.png" width="17" height="17" alt="" /></a>

</td>
<td width="1%" class="noir">
 <?php
 
 
 echo '<input type="checkbox" name="check[]"  value="'. $datas['id'].' "/>';
 $id =$datas['id'];
if (isset($_POST['check'])) {
    $id = implode(',', $_POST['check']);
    $sql = "UPDATE materiels3 SET disponibilite='',chantier='',nom_retrait='',date_sortie='' WHERE id IN (".$id.")";
   $result=mysql_query($sql);

//en cas d'échec de la mise à jour, on affiche le message d'erreur
  if (!$result) {
   echo "erreur sql liée  à la mise à jour:\n" ;
    die( mysql_error());
}
 }

?>

</td>
<?php
  echo '</tr>';
  }//fin de while???je suppose
   echo '<input name="OK" type="submit" /></form>';
  echo '</tbody>';
  echo '<tfoot><tr><th colspan="12">&nbsp;</th></tr></tfoot>';
  echo '</table>';
  mysql_free_result($req);
  mysql_close();
 
 }  // ON FERME GESTION DES ETATS DES PRETS MATERIELS - ACTION 11 //
?>

Eléphant du PHP | 134 Messages

22 sept. 2013, 15:38

OK

Merci beaucoup je vais voir ça et tiens au courant .

Eléphant du PHP | 134 Messages

22 sept. 2013, 16:38

Merci c bon ouf c résolu grâce a vous et une connaissance membre de php france

<td width="1%" class="noir">
 
 <?php
 echo '<input type="checkbox" name="check[]"  value="'. $datas['id'].' "/>';

?>
 

</td>
<?php
  echo '</tr>';
  }
 
  echo '</tbody>';
  echo '<tfoot><tr><th colspan="12">&nbsp;</th></tr></tfoot>';
  echo '</table>';
  echo '<table><tr><td><input name="Update" value="OK" type="submit" /></form></td></tr></table>';
  mysql_free_result($req);
  
  if (isset($_POST['Update'])) {
    $id = implode(',', $_POST['check']);
    $sql = "UPDATE materiels3 SET disponibilite='',chantier='',nom_retrait='',date_sortie='' WHERE id IN (".$id.")";
   $result=mysql_query($sql);


//en cas d'échec de la mise à jour, on affiche le message d'erreur
  if (!$result) {
   echo "erreur sql liée  à la mise à jour:\n" ;
    die( mysql_error());
}
 }
  mysql_close();
  
 }  // ON FERME GESTION DES ETATS DES PRETS MATERIELS - ACTION 11 //
?>  


Merci beaucoup pour votre aide !!
Modifié en dernier par Michel6359 le 22 sept. 2013, 17:24, modifié 1 fois.

Eléphant du PHP | 134 Messages

22 sept. 2013, 17:20

Maintenant je voudrai faire en sorte d'une création d'archive des retours matériels , là ça fonctionne mais je coche plusieurs boite a cocher , ils sont en état de retour , mais l'archive n'enregistre que 1 retour dans ma table , il faudrait faire une boucle je pense pour enregistrer dans la table archive pour tout les matériels , j'ai fais ça mais ça enregistre que 1 . Donc voir une boucle ou j'ai mal placé ma requête enregistrement. Merci pour votre aide

<td width="1%" class="noir">
 
 <?php
 echo '<input type="checkbox" name="check[]"  value="'. $datas['id'].' "/>';

   ?>
 

</td>
<?php
  echo '</tr>';
  }
 
  echo '</tbody>';
  echo '<tfoot><tr><th colspan="12">&nbsp;</th></tr></tfoot>';
  echo '</table>';
  echo '<table><tr><td><input name="Update" value="Valider les Retours Matériels" type="submit" /></form></td></tr></table>';
  mysql_free_result($req);
  
  if (isset($_POST['Update'])) {
    $id = implode(',', $_POST['check']);
    $sql = "UPDATE materiels3 SET disponibilite='',chantier='',nom_retrait='',date_sortie='' WHERE id IN (".$id.")";
    $result=mysql_query($sql);
    
	
//en cas d'échec de la mise à jour, on affiche le message d'erreur
  if (!$result) {
   echo "erreur sql liée  à la mise à jour:\n" ;
    die( mysql_error());
}
    // ENREGISTREMENT ARCHIVE //
	$list_retour = mysql_query("SELECT id,designation,reference,date_sortie,nom_retrait,chantier FROM materiels3 WHERE id='$id'");
	$materiel_retour = mysql_fetch_array($list_retour);
	
	// VARIABLES //
	$designation = $materiel_retour[1];
	$reference = $materiel_retour[2];
	$date_sortie = $materiel_retour[3];
	$nom_retrait = $materiel_retour[4];
	$chantier = $materiel_retour[5];
	$date_retour =  date('Y/m/d') ; // date du jour du retour Matériel //
	
	// ENREGISTREMENT //
     $sql2 = mysql_query("INSERT INTO Archive_sortie VALUES('',now(),'$designation','$reference','$date_sortie','$nom_retrait','$chantier','$date_retour')"); 
	 $result2=mysql_query($sql2);
 
 }
  mysql_close();
  
 }  // ON FERME GESTION DES ETATS DES PRETS MATERIELS - ACTION 11 //
?>  

Mammouth du PHP | 571 Messages

22 sept. 2013, 22:15

tu n'as nullement besoin d’insérer toutes les informations d'un matériel dans la table Archive_sortie car un matériel est ou doit être identifié de manière unique par son id(clé primaire). Je te suggère de revoir la modélisation de la table Archive_sortie qui peut prendre 2 colonnes(id,materiel_id):
CREATE  TABLE IF NOT EXISTS Archive_sortie (
  `id` INT NOT NULL AUTO_INCREMENT ,
  materiel_id INT NOT NULL ,
   PRIMARY KEY (`id`) ,
    FOREIGN KEY (materiel_id) REFERENCES materiel(id)
)
On a maintenant une table Archive_sortie qui est associée à la table matériel par une clé étrangère(materiel_id).Par ailleurs si tu souhaites extraire les archives des matériels tu peux faire une requête sql avec jointure entre la table matériel et Archive_sortie.


Pour inserer les ids(exemple 3 ids de valeur 1,2,3) dans la table Archive_sortie :
INSERT INTO Archive_sortie(materiel_id) VALUES(1),(2),(3)
Dès lors insérer les données en provenance des checkbox revient à implémenter ceci:


<td width="1%" class="noir">
 
 <?php
 echo '<input type="checkbox" name="check[]"  value="'. $datas['id'].' "/>';

   ?>
 

</td>
<?php
  echo '</tr>';
  }
 
  echo '</tbody>';
  echo '<tfoot><tr><th colspan="12">&nbsp;</th></tr></tfoot>';
  echo '</table>';
  echo '<table><tr><td><input name="Update" value="Valider les Retours Matériels" type="submit" /></form></td></tr></table>';
  mysql_free_result($req);
 
  if (isset($_POST['Update'])) {
    $id = implode(',', $_POST['check']);
    $sql = "UPDATE materiels3 SET disponibilite='',chantier='',nom_retrait='',date_sortie='' WHERE id IN (".$id.")";
    $result=mysql_query($sql);
   
       
//en cas d'échec de la mise à jour, on affiche le message d'erreur
  if (!$result) {
   echo "erreur sql liée  à la mise à jour:\n" ;
    die( mysql_error());
}
    // ENREGISTREMENT ARCHIVE //
       $idTab=array();
	//parcours du array des ids reçus
	foreach($_POST['check'] as $val) { 
	$idTab[]="($val)"; //
	}
	$insertSql="INSERT INTO Archive_sortie(materiel_id) VALUES".implode(',',$idTab);


       
         $result2=mysql_query($insertSql);
        //en cas d'échec d'insertion, on affiche le message d'erreur
  if (!$result2) {
   echo "erreur sql liée  à l'insertion:\n" ;
    die( mysql_error());
 }else{
  echo "archivage effectué avec succès";
 }
 }
  mysql_close();
 
 }  // ON FERME GESTION DES ETATS DES PRETS MATERIELS - ACTION 11 //
?>  
 

Eléphant du PHP | 134 Messages

22 sept. 2013, 22:34

Bonsoir

Ok merci pour toutes ces infos , demain je vais regarder tout ça.

Mais , avec ta proposition l'archive ne me dira pas qui a utilisé le matériel à une date , car l'archive doit contenir le matériel , utilisé par (Nom) , sortie le (date_sortie) , retour (date_retour), pour le chantier (chantier) ?



Bonne soirée et encore merci de ton aide