[PHP] Mise à jours table pour chaque ligne de l'array en une fois

Eléphant du PHP | 175 Messages

16 mai 2008, 12:22

Parse error: syntax error, unexpected T_IF in D:\gmf\apps\homol\webwasher\administration_test.php on line 95

Ligne 95 :

if ($etat=="Verification") echo ' selected="selected"';
echo '<option value="Verification"'; au lieu de echo '<option value="Verification"',

tu peut rempalcer les , de fin de lignes par des ;
mais la faut chercher un peu...

Petit nouveau ! | 9 Messages

16 mai 2008, 13:31

ok pour le ; j'avais capter mais je voulais être sur.

Par contre ça ne fonctionne pas ça me retourne toujours la valeur prédéfini dans la base : En cours
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
		<meta http-equiv="content-language" content="fr">
		<title>Administration</title>
		<style type="text/css">
			body {margin: 0;font-family: Arial;color: #000000;font-size: 10pt;}
			a:link {text-decoration: none;}
			a:visited {text-decoration: none;}
			a:active {text-decoration: none;}
			a:hover {text-decoration: none;}
			a {color: #333399; font-weight: bold;}
			a:hover {color: #FF0000;}
			table td {background-color: #CCCCCC; margin: 0; border-width: 0; font-family: Arial; color: #000000; font-size: 10pt;}
			.title {background-color: #33CCCC; margin: 0; border-width: 0; font-family: Arial; color: #000000; font-size: 11pt;}
		</style>
	</head>
	<body>
		<center><h2>Reste à faire</h2></center>

		<?php 
    include ('include/connexion.php'); 
    $connexion=connexion(); 
    //en cas de soumission du formulaire on va modifier chaque id...
    if ($_POST){
        if (is_array($_POST['etat'])){
            foreach ($_POST['etat'] as $cle=>$valeur){
                $upd = 'UPDATE formulaire SET etat="'.$valeur.'" WHERE id="'.$cle.'"'; 
                mysql_query($upd); 
            }
        }
    }
    
    //on recupere les valeurs de la base:
    $sql = "SELECT * FROM formulaire ORDER BY `formulaire`.`id` DESC"; 
    $result=mysql_query($sql); 
     
    echo "<table border=\"1\" width=\"100%\" align=\"center\"> 
    <tr> 
    <td class=\"title\" align=\"center\">&nbsp;N°&nbsp;</td> 
    <td class=\"title\" align=\"center\">&nbsp;Identifiant&nbsp;</td> 
    <td class=\"title\" align=\"center\">&nbsp;Nom&nbsp;</td> 
    <td class=\"title\" align=\"center\">&nbsp;Prénom&nbsp;</td> 
    <td class=\"title\" align=\"center\">&nbsp;Service&nbsp;</td> 
    <td class=\"title\" align=\"center\">&nbsp;Téléphone&nbsp;</td> 
    <td class=\"title\" align=\"center\">&nbsp;Nom du site&nbsp;</td> 
    <td class=\"title\" align=\"center\">&nbsp;URL&nbsp;</td> 
    <td class=\"title\" align=\"center\">&nbsp;Catégorie&nbsp;</td> 
    <td class=\"title\" align=\"center\">&nbsp;Motivation de la demande&nbsp;</td> 
    <td class=\"title\" align=\"center\">&nbsp;Date&nbsp;</td> 
    <td class=\"title\" align=\"center\">&nbsp;Etat&nbsp;</td> 
    <td class=\"title\" align=\"center\">&nbsp;Commentaire&nbsp;</td> 
    </tr>"; 
     
    //$tableau = mysql_fetch_array($result); 
     
    while ($tableau = mysql_fetch_row($result)) 
        { 
            $id=$tableau[0]; 
            $identifiant=$tableau[1]; 
            $ndemandeur=$tableau[2]; 
            $prenom=$tableau[3]; 
            $service=$tableau[4]; 
            $telephone=$tableau[5]; 
            $nsi=$tableau[6]; 
            $url=$tableau[7]; 
            $categorie=$tableau[8]; 
            $mdld=$tableau[9]; 
            $date=$tableau[10]; 
            $etat=$tableau[11]; 
            $com=$tableau[12]; 
?> 


<form method="post" action="administration_test.php"> 
<?php 
     

    echo "<tr> 
         <td align=\"center\">$id&nbsp;</td> 
         <td>$identifiant&nbsp;</td> 
         <td>$ndemandeur&nbsp;</td> 
         <td>$prenom&nbsp;</td> 
         <td>$service&nbsp;</td> 
         <td>$telephone&nbsp;</td> 
         <td>$nsi&nbsp;</td> 
         <td><a href=\"$url\" target=\"_blank\">$url</a>&nbsp;</td> 
         <td>$categorie&nbsp;</td> 
         <td>$mdld&nbsp;</td> 
         <td align=\"center\">$date&nbsp;</td> 
        <td align=\"center\">";
        echo "<td align=\"center\">
		<select size=\"1\" name=\"etat['.$id.']\" tabindex=\"3\">";
        echo "<option value=\"$etat\">$etat</option>";
		
		echo '<option value="Verification"'; 
            if ($etat=="Verification") echo ' selected="selected"'; 
            echo '>Verification</option>';
            
            echo '<option value="Autorisation"';
            if ($etat=="Autorisation") echo ' selected="selected"'; 
            echo '>Autorisation</option>';
            
            echo '<option value="Accepter"';
            if ($etat=="Accepter") echo ' selected="selected"'; 
            echo '>Accepter</option>';
            
            echo '<option value="Refuser"';
            if ($etat=="Refuser") echo ' selected="selected"'; 
            echo '>Refuser</option>';
        echo '</select>';
            
        echo "<td align=\"center\"><textarea rows='5' cols='15' name='comen'>$com</textarea></td> 
            </tr>"; 
             
    } 
    echo "</table> 
    <br><center><input type=\"submit\" value=\"Enregistrer\"></center>"; 
    ?> 
</form>
</form>

				<br>
	</body>
</html>


Eléphant du PHP | 175 Messages

16 mai 2008, 14:07

as tu essaye de debugger?

- voir le code source généré
- voir si les valeurs sont bien postées
- voir si on passe bien dans les differentes conditions
- voir la requete d'update
- etc...

juste dire que ca ne marche pas ne nous suffit pas ;)

c'est pas nous qui devons faire tout le boulot mais on essaye juste de t'aiguiller pour progresser

Edit: il doit y avoir une erreur ici
 
echo "<td align=\"center\"> 
        <select size=\"1\" name=\"etat['.$id.']\" tabindex=\"3\">";
a remplacer par
echo "<td align=\"center\"> 
        <select size=\"1\" name=\"etat[$id]\" tabindex=\"3\">";

Petit nouveau ! | 9 Messages

16 mai 2008, 14:13

mais je cherche j'essaye plein de truc t'inquiete.

Mais là je te dis un grand bravo ça fonctionne à merveille.

Merci merci merci