IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PHP & Base de données Discussion :

garder un chekbox checked [MySQL]


Sujet :

PHP & Base de données

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mai 2012
    Messages
    42
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Mai 2012
    Messages : 42
    Points : 29
    Points
    29
    Par défaut garder un chekbox checked
    Bonsoir à tous,
    J'ai 2 formulaires de types checkbox, "preparation" et "livraison", qui se trouvent eux-mêmes dans des tableaux générés dynamiquement.
    Je voudrais garder les checkbox qui se trouvent dans ces formulaires
    checkées quand on recharge la page, après avoir cliqué sur le bouton 'ok'.
    D'abord, je dois écrire la valeur 1 dans les champs preparation_commande et livraison_commande(boolean) qui se trouvent dans ma table commandes_clients, mais je n'y arrive même pas...ensuite je devrais pouvoir récupérer cette valeur 1
    et mettre le chekbox en checked.
    Je n'ai pas d'erreur mais toutes mes cases sont décochées au réaffichage de la page, et j'écris rien dans ma BD. Si qqn voit comment faire pour arriver au résultat souhaité, il est le bienvenu. Merci.
    J'ai mis une image du formulaire en attachement, ainsi qu'une image de la table commandes_clients...
    Et voici mon code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
     
    <form style="text-align:center;" method="post" action="admin.php">
     
    			<table align="center" width="250">
    				<tr>
    					<td colspan="2" style="text-align:center"><input class="submit" name="commandes" type="submit" value="Commandes" /></td>
    				</tr>
    			</table>
     
    </form>
    <?php
    if(isset($_POST['commandes']))
    {
    	if($connection = ConnectBD())
    			{
    			$sql ='SELECT prenom_user, nom_user, adresse_user, cp_user, tel_user, ref_produit, quantite_produit_commande, ref_commande_client
    				   FROM produits_commandes
    				   INNER JOIN commandes_clients ON produits_commandes.ref_commande_client=commandes_clients.id_commande_client
    				   INNER JOIN users ON commandes_clients.ref_user=users.email_user
    				   WHERE date_commande=CURRENT_DATE()';
    			if($requete = TraiterRequete($sql))
    			{
    				echo '<table class="propricom">
    					  <tbody>
    					  <tr>
    					  <th class="propricomtitles">Prénom</th>
    					  <th class="propricomtitles">Nom</th>
    					  <th class="propricomtitles">Adresse</th>
    					  <th class="propricomtitles">CP</th>
    					  <th class="propricomtitles">Téléphone</th>
    					  <th class="propricomtitles">Code produit</th>
    					  <th class="propricomtitles">Quantité</th>
    					  <th class="propricomtitles">N°commande</th>
    					  <th class="propricomtitles">Préparation</th>
    					  <th class="propricomtitles">Livraison</th>
    					  </tr>';
    				$b=0;								  
    				while($data = mysql_fetch_array($requete))
    				{
    					$a=$data['ref_commande_client'];
    					if($b!=$a)
    					{
    						echo '<tr>';
    						echo '<td class="produits2">'.$data['prenom_user'].'</td><td class="produits2">'.$data['nom_user'].'</td><td class="produits2">'.$data['adresse_user'].'</td><td class="produits2">'.$data['cp_user'].'</td><td class="produits2">'.$data['tel_user'].'</td><td class="produits2">'.$data['ref_produit'].'</td><td class="produits2">'.$data['quantite_produit_commande'].'</td><td class="produits2">'.$data['ref_commande_client'].'</td>
    						<td class="produits2">
    						<form method="post" action="admin.php">
    						<input type="submit" name="ok1" value="ok" />
    						<input type="checkbox" name="preparation" value="" ';
    						if(isset($_POST['ok1']) && !empty($_POST['preparation']))
    						{
    							echo 'checked="checked"';
    							$sql2='UPDATE commandes_clients SET preparation_commande=1 WHERE id_commande_client="'.$data['ref_commande_client'].'"';
    							$requete2 = TraiterRequete($sql2);
    						}
    						echo' />
    						</form>
    						</td>
    						<td class="produits2">
    						<form method="post" action="admin.php">
    						<input type="submit" name="ok2" value="ok" />
    						<input type="checkbox" name="livraison" value="" ';
    						if(isset($_POST['ok2']) && !empty($_POST['livraison']))
    						{
    							echo 'checked="checked"';
    							$sql3='UPDATE commandes_clients SET livraison_commande=1 WHERE id_commande_client="'.$data['ref_commande_client'].'"';
    							$requete3 = TraiterRequete($sql3);
    						}
    						echo' />
    						</form>
    						</td>';
    						echo '</tr>';
    					}
    					else
    					{
    						echo '<tr>';
    						echo '<td class="produits"></td><td class="produits"></td><td class="produits"></td><td class="produits"></td><td class="produits"></td><td class="produits">'.$data['ref_produit'].'</td><td class="produits">'.$data['quantite_produit_commande'].'</td><td class="produits"></td><td class="produits"></td><td class="produits"></td>';
    						echo '</tr>';
    					}
    					$b=$data['ref_commande_client'];
    				}
    				echo'</tbody>
    				       </table>';
    			}
    		}mysql_close($connection);	
    }
    ?>
    Images attachées Images attachées   

  2. #2
    Membre actif
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mai 2012
    Messages
    131
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Mai 2012
    Messages : 131
    Points : 242
    Points
    242
    Par défaut
    Bonjour,

    déjà il faut remplir le value des tes inputs preparation et livraison

    la condition
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    !empty($_POST['preparation'])  et !empty($_POST['livraison']
    ne sera jamais realisé

  3. #3
    Membre expert Avatar de Fench
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mai 2002
    Messages
    2 353
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Groenland

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Mai 2002
    Messages : 2 353
    Points : 3 390
    Points
    3 390
    Par défaut
    Bonjour,

    Ton problème est que tu boucles:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    while($data = mysql_fetch_array($requete))
    en créant à chaque fois deux formulaires:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    <form method="post" action="admin.php">
    						<input type="submit" name="ok1" value="ok" />
    						<input type="checkbox" name="preparation" value="" ';
    Comment tu veux que ton appli différencie tous les submit name ok1 par ex ????

    Deux solutions:
    1) un indice dans tous tes formulaires
    2) un formulaire unique avec deux tableaux de checkbox
    Meuuh en AI à l'INRA
    Domaines: {java, php, js, jquery}{hibernate, doctrine}{MyLib, symfony, Zend}
    fait gagner du temps à ceux qui aident , donc un message avec la balise résolu laisse plus de temps pour résoudre d'autres problèmes (balise à cliquer en bas de l'écran)

  4. #4
    Nouveau membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mai 2012
    Messages
    42
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Mai 2012
    Messages : 42
    Points : 29
    Points
    29
    Par défaut
    Merci à tous les 2, de proposer des solutions.

    J'ai essayé avec 1 seul formulaire et un seul submit, mais je n'arrive tjrs pas à faire l'update dans la BD. Je crois que la condition if(isset($_POST['valider'])) ne peut jamais être remplie à cet endroit, mais je ne sais pas où la placer.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
     
    <form style="text-align:center;" method="post" action="admin.php">
     
    			<table align="center" width="250">
    				<tr>
    					<td colspan="2" style="text-align:center"><input class="submit" name="commandes" type="submit" value="Commandes" /></td>
    				</tr>
    			</table>
     
    </form>
    <?php
    if(isset($_POST['commandes']))
    {
    	if($connection = ConnectBD())
    			{
    			$sql ='SELECT prenom_user, nom_user, adresse_user, cp_user, tel_user, ref_produit, quantite_produit_commande, ref_commande_client
    				   FROM produits_commandes
    				   INNER JOIN commandes_clients ON produits_commandes.ref_commande_client=commandes_clients.id_commande_client
    				   INNER JOIN users ON commandes_clients.ref_user=users.email_user
    				   WHERE date_commande=CURRENT_DATE()';
    			if($requete = TraiterRequete($sql))
    			{
    				echo '<form method="post" action="admin.php">';
    				echo '<table class="propricom">
    					  <tbody>
    					  <tr>
    					  <th class="propricomtitles">Prénom</th>
    					  <th class="propricomtitles">Nom</th>
    					  <th class="propricomtitles">Adresse</th>
    					  <th class="propricomtitles">Téléphone</th>
    					  <th class="propricomtitles">Code produit</th>
    					  <th class="propricomtitles">Quantité</th>
    					  <th class="propricomtitles">N°commande</th>
    					  <th class="propricomtitles">Montant</th>
    					  <th class="propricomtitles">Préparation</th>
    					  <th class="propricomtitles">Livraison</th>
    					  </tr>';
    				$b=0;								  
    				while($data = mysql_fetch_array($requete))
    				{
    					$sql2='SELECT SUM( quantite_produit_commande * prix_produit_htva ) pchtva
    						   FROM produits
    						   INNER JOIN produits_commandes ON produits.code_produit = produits_commandes.ref_produit
    						   WHERE ref_commande_client ="'.$data['ref_commande_client'].'"';
    					$requete2 = TraiterRequete($sql2);
    					$data2 = mysql_fetch_array($requete2);
    					$a=$data['ref_commande_client'];
    					if($b!=$a)
    					{
     
    							//$_SESSION['id_commande_client']=$data['ref_commande_client'];
    							echo '<tr>';
    							echo '<td class="produits2">'.$data['prenom_user'].'</td><td class="produits2">'.$data['nom_user'].'</td><td class="produits2">'.$data['adresse_user'].'</td><td class="produits2">'.$data['tel_user'].'</td><td class="produits2">'.$data['ref_produit'].'</td><td class="produits2">'.$data['quantite_produit_commande'].'</td><td class="produits2">'.$data['ref_commande_client'].'</td><td class="produits2">'.$data2['pchtva'].' €</td>
    							<td class="produits2">
    							<input type="checkbox" name="preparation" value="" ';
    							if(isset($_POST['valider']))
    							{
    								$sql3='UPDATE commandes_clients SET preparation_commande="1" WHERE id_commande_client="'.$data['ref_commande_client'].'"';
    								$requete3 = TraiterRequete($sql3);
    								echo 'checked="checked"';
    							}
    							echo'/></td>
    							<td class="produits2">	
    							<input type="checkbox" name="livraison" value="" ';
    							if(isset($_POST['valider']))
    							{
    								$sql4='UPDATE commandes_clients SET livraison_commande="1" WHERE id_commande_client="'.$data['ref_commande_client'].'"';
    								$requete4 = TraiterRequete($sql4);
    								echo 'checked="checked"';
    							}
    							echo'/></td>';
    							echo '</tr>';
     
    					}
    					else
    					{
    						echo '<tr>';
    						echo '<td class="produits"></td><td class="produits"></td><td class="produits"></td><td class="produits"></td><td class="produits">'.$data['ref_produit'].'</td><td class="produits">'.$data['quantite_produit_commande'].'</td><td class="produits"></td><td class="produits"></td><td class="produits"></td><td class="produits"></td>';
    						echo '</tr>';
    					}
    					$b=$data['ref_commande_client'];
    				}
    				echo'</tbody>
    					 </table>';
    				echo'<input name="valider" type="submit" value="Valider" />
    					 </form>';	 
    			}
    		}mysql_close($connection);	
    }
    ?>
    Par contre si je fais le traitement à part en utilisant le code ci-dessous, l'update fonctionne mais uniquement pour le dernier checkbox (même si je les coche tous).

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    <?php
    session_start();
    include('fonctions.php'); 
    if(isset($_POST['valider']))
    {
    	$connection = ConnectBD();
    	$sql='UPDATE commandes_clients SET preparation_commande="1" WHERE id_commande_client="'.$_SESSION['id_commande_client'].'"';
    	$requete = TraiterRequete($sql);
    	mysql_close($connection);
    }
    header("location: admin.php");
    ?>

  5. #5
    Nouveau membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mai 2012
    Messages
    42
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Mai 2012
    Messages : 42
    Points : 29
    Points
    29
    Par défaut
    Bon,
    j'ai déplacé le isset en début de code et maintenant évidemment si je clique sur 1 checkbox puis que je clique sur valider tous
    mes checkbox sont remplis et tous les champs de ma table sont remplacés par 1, donc je ne suis pas plus avancé...
    Je n'arrive qu'à déplacer le problème. Je comprends pq ça ne fonctionne pas mais je sais pas comment faire pour que ça fonctionne; et je veux avoir des chekbox séparés pour chaque commande(je ne peux pas mettre seulement 2 checxbox comme tu me l'a proposé Fench).
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
     
    <form style="text-align:center;" method="post" action="admin.php">
     
    			<table align="center" width="250">
    				<tr>
    					<td colspan="2" style="text-align:center"><input class="submit" name="commandes" type="submit" value="Commandes" /></td>
    				</tr>
    			</table>
     
    </form>
    <?php
    if(isset($_POST['commandes']) || isset($_POST['valider']))
    {
    	if($connection = ConnectBD())
    			{
    			$sql ='SELECT prenom_user, nom_user, adresse_user, cp_user, tel_user, ref_produit, quantite_produit_commande, ref_commande_client
    				   FROM produits_commandes
    				   INNER JOIN commandes_clients ON produits_commandes.ref_commande_client=commandes_clients.id_commande_client
    				   INNER JOIN users ON commandes_clients.ref_user=users.email_user
    				   WHERE date_commande=CURRENT_DATE()';
    			if($requete = TraiterRequete($sql))
    			{
    				echo '<form method="post" action="admin.php">';
    				echo '<table class="propricom">
    					  <tbody>
    					  <tr>
    					  <th class="propricomtitles">Prénom</th>
    					  <th class="propricomtitles">Nom</th>
    					  <th class="propricomtitles">Adresse</th>
    					  <th class="propricomtitles">Téléphone</th>
    					  <th class="propricomtitles">Code produit</th>
    					  <th class="propricomtitles">Quantité</th>
    					  <th class="propricomtitles">N°commande</th>
    					  <th class="propricomtitles">Montant</th>
    					  <th class="propricomtitles">Préparation</th>
    					  <th class="propricomtitles">Livraison</th>
    					  </tr>';
    				$b=0;								  
    				while($data = mysql_fetch_array($requete))
    				{
    					$sql2='SELECT SUM( quantite_produit_commande * prix_produit_htva ) pchtva
    						   FROM produits
    						   INNER JOIN produits_commandes ON produits.code_produit = produits_commandes.ref_produit
    						   WHERE ref_commande_client ="'.$data['ref_commande_client'].'"';
    					$requete2 = TraiterRequete($sql2);
    					$data2 = mysql_fetch_array($requete2);
    					$a=$data['ref_commande_client'];
    					if($b!=$a)
    					{
     
    							//$_SESSION['id_commande_client']=$data['ref_commande_client'];
    							echo '<tr>';
    							echo '<td class="produits2">'.$data['prenom_user'].'</td><td class="produits2">'.$data['nom_user'].'</td><td class="produits2">'.$data['adresse_user'].'</td><td class="produits2">'.$data['tel_user'].'</td><td class="produits2">'.$data['ref_produit'].'</td><td class="produits2">'.$data['quantite_produit_commande'].'</td><td class="produits2">'.$data['ref_commande_client'].'</td><td class="produits2">'.$data2['pchtva'].' €</td>
    							<td class="produits2">
    							<input type="checkbox" name="preparation" value="" ';
    							if(isset($_POST['valider']))
    							{
    								$sql3='UPDATE commandes_clients SET preparation_commande="1" WHERE id_commande_client="'.$data['ref_commande_client'].'"';
    								$requete3 = TraiterRequete($sql3);
    								echo 'checked="checked"';
    							}
    							echo'/></td>
    							<td class="produits2">	
    							<input type="checkbox" name="livraison" value="" ';
    							if(isset($_POST['valider']))
    							{
    								$sql4='UPDATE commandes_clients SET livraison_commande="1" WHERE id_commande_client="'.$data['ref_commande_client'].'"';
    								$requete4 = TraiterRequete($sql4);
    								echo 'checked="checked"';
    							}
    							echo'/></td>';
    							echo '</tr>';
     
    					}
    					else
    					{
    						echo '<tr>';
    						echo '<td class="produits"></td><td class="produits"></td><td class="produits"></td><td class="produits"></td><td class="produits">'.$data['ref_produit'].'</td><td class="produits">'.$data['quantite_produit_commande'].'</td><td class="produits"></td><td class="produits"></td><td class="produits"></td><td class="produits"></td>';
    						echo '</tr>';
    					}
    					$b=$data['ref_commande_client'];
    				}
    				echo'</tbody>
    					 </table>';
    				echo'<input name="valider" type="submit" value="Valider" />
    					 </form>';	 
    			}
    		}mysql_close($connection);	
    }
    ?>
    Images attachées Images attachées  

  6. #6
    Membre expert Avatar de Fench
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mai 2002
    Messages
    2 353
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Groenland

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Mai 2002
    Messages : 2 353
    Points : 3 390
    Points
    3 390
    Par défaut
    Non non

    Dans le dernier code tu ne différencies pas les checkbox !!!

    J'ai pris un peu de temps ce matin et je te donne le code qui devrait être bon (ou au moins de manière à comprendre)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
     
    <?php
    if(isset($_POST['commandes']) || isset($_POST['valider']))
    {
        if($connection = ConnectBD()){
            $sql ='SELECT ... ';
     
                if($requete = TraiterRequete($sql)) {
     
                    echo '<form method="post" action="admin.php">';
                    echo '<table class="propricom"><tbody><tr><!-- Les entêtes --></tr>';
     
                        $b=0;
     
                        // ICI déclaration de l'index de parcours de tableau
                        $indexLigneCourante=0;
     
                        while($data = mysql_fetch_array($requete)) {
     
                                $sql2='SELECT ... WHERE ref_commande_client ="'.$data['ref_commande_client'].'"';
                                $requete2 = TraiterRequete($sql2);
     
                                $data2 = mysql_fetch_array($requete2);
                                $a=$data['ref_commande_client'];
     
                                if($b!=$a) {
     
                                    //$_SESSION['id_commande_client']=$data['ref_commande_client'];
                                    echo '<tr>';
                                    echo '<td class="produits2">'.$data['prenom_user'].'</td><td class="produits2">'.$data['nom_user'].'</td><td class="produits2">'.$data['adresse_user'].'</td><td class="produits2">'.$data['tel_user'].'</td><td class="produits2">'.$data['ref_produit'].'</td><td class="produits2">'.$data['quantite_produit_commande'].'</td><td class="produits2">'.$data['ref_commande_client'].'</td><td class="produits2">'.$data2['pchtva'].' €</td>
                                    <td class="produits2">
                                    
                                    <!-- ICI LA MODIF sur le tableau de CHECKBOX ce qui permet de les différencier -->
                                    <input type="checkbox" name="preparation[]" value="" ';
     
                                    // ICI LA MODIF sur le tableau de checkbox à 1 oui ou non pour celui ci précisement 
                                    if(isset($_POST['valider']) && $_POST['preparation'][$indexLigneCourante]){
     
                                        $sql3='UPDATE commandes_clients SET preparation_commande="1" WHERE id_commande_client="'.$data['ref_commande_client'].'"';
                                        $requete3 = TraiterRequete($sql3);
                                        echo 'checked="checked"';
                                    }
     
                                    // De même avec l'autre tableau de checkbox
     
                                } else {
                                    echo '<tr>';
                                    echo '<td class="produits"></td><td class="produits"></td><td class="produits"></td><td class="produits"></td><td class="produits">'.$data['ref_produit'].'</td><td class="produits">'.$data['quantite_produit_commande'].'</td><td class="produits"></td><td class="produits"></td><td class="produits"></td><td class="produits"></td>';
                                    echo '</tr>';
                                }
                                $b=$data['ref_commande_client'];
     
                                // ICI l'incrémentation pour voir où l'on se place dans le tableau
                                $indexLigneCourante++;
                        }
     
                    echo'</tbody></table>';
                    echo'<input name="valider" type="submit" value="Valider" /></form>';	 
                }
        }
        mysql_close($connection);	
    }
    ?>
    Meuuh en AI à l'INRA
    Domaines: {java, php, js, jquery}{hibernate, doctrine}{MyLib, symfony, Zend}
    fait gagner du temps à ceux qui aident , donc un message avec la balise résolu laisse plus de temps pour résoudre d'autres problèmes (balise à cliquer en bas de l'écran)

  7. #7
    Nouveau membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mai 2012
    Messages
    42
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Mai 2012
    Messages : 42
    Points : 29
    Points
    29
    Par défaut
    merci beaucoup Fench, je te donne des nouvelles dès que j'ai le temps de me pencher sur ton code.

  8. #8
    Nouveau membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mai 2012
    Messages
    42
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Mai 2012
    Messages : 42
    Points : 29
    Points
    29
    Par défaut
    Grâce à la patience et aux indications de Fench, j'ai pu modifier mon code
    pour arriver à garder mes checkbox checkées après validation mais je n'arrive tjrs pas à les garder cochées après avoir changé de page sur le site...

    actuellement mon code ressemble à ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
     
    <?php
    if(isset($_POST['commandes']) || isset($_POST['valider']))
    {
    	if($connection = ConnectBD())
    			{
    			$sql ='SELECT prenom_user, nom_user, adresse_user, cp_user, tel_user, ref_produit, quantite_produit_commande, ref_commande_client
    				   FROM produits_commandes
    				   INNER JOIN commandes_clients ON produits_commandes.ref_commande_client=commandes_clients.id_commande_client
    				   INNER JOIN users ON commandes_clients.ref_user=users.email_user
    				   WHERE date_commande=CURRENT_DATE()';
    			if($requete = TraiterRequete($sql))
    			{
    				echo '<form method="post" action="admin.php">';
    				echo '<table class="propricom">
    					  <tbody>
    					  <tr>
    					  <th class="propricomtitles">Prénom</th>
    					  <th class="propricomtitles">Nom</th>
    					  <th class="propricomtitles">Adresse</th>
    					  <th class="propricomtitles">Téléphone</th>
    					  <th class="propricomtitles">Code produit</th>
    					  <th class="propricomtitles">Quantité</th>
    					  <th class="propricomtitles">N°commande</th>
    					  <th class="propricomtitles">Montant</th>
    					  <th class="propricomtitles">Préparation</th>
    					  <th class="propricomtitles">Livraison</th>
    					  </tr>';
    				$b=0;
    				$indexLigneCourante=0;
    				while($data = mysql_fetch_array($requete))
    				{
    					$sql2='SELECT SUM( quantite_produit_commande * prix_produit_htva ) pchtva
    						   FROM produits
    						   INNER JOIN produits_commandes ON produits.code_produit = produits_commandes.ref_produit
    						   WHERE ref_commande_client ="'.$data['ref_commande_client'].'"';
    					$requete2 = TraiterRequete($sql2);
    					$data2 = mysql_fetch_array($requete2);
    					$a=$data['ref_commande_client'];
    					if($b!=$a)
    					{
     
    							echo '<tr>';
    							echo '<td class="produits2">'.$data['prenom_user'].'</td><td class="produits2">'.$data['nom_user'].'</td><td class="produits2">'.$data['adresse_user'].'</td><td class="produits2">'.$data['tel_user'].'</td><td class="produits2">'.$data['ref_produit'].'</td><td class="produits2">'.$data['quantite_produit_commande'].'</td><td class="produits2">'.$data['ref_commande_client'].'</td><td class="produits2">'.$data2['pchtva'].' €</td>
    							<td class="produits2">
    							<input type="checkbox" name="preparation[]" value="" ';
    							if(isset($_POST['valider']) && isset($_POST['preparation'][$indexLigneCourante]))
    							{
    								$sql3='UPDATE commandes_clients SET preparation_commande="1" WHERE id_commande_client="'.$data['ref_commande_client'].'"';
    								$requete3 = TraiterRequete($sql3);
    								$sql3b='SELECT preparation_commande FROM commandes_clients WHERE id_commande_client="'.$data['ref_commande_client'].'"';
    								$requete3b = TraiterRequete($sql3b);
    								$data3b = mysql_fetch_array($requete3b);
    								$_SESSION['preparation_commande'][$indexLigneCourante]=$data3b['preparation_commande'];
    								if($_SESSION['preparation_commande'][$indexLigneCourante]==1)
    								{
    									echo 'checked="checked"';
    								}
    								else
    								{
    									echo'';
    								}
    							}
    							echo'/></td>
    							<td class="produits2">	
    							<input type="checkbox" name="livraison[]" value="" ';
    							if(isset($_POST['valider']) && isset($_POST['livraison'][$indexLigneCourante]))
    							{
    								$sql4='UPDATE commandes_clients SET livraison_commande="1" WHERE id_commande_client="'.$data['ref_commande_client'].'"';
    								$requete4 = TraiterRequete($sql4);
    								$sql4b='SELECT livraison_commande FROM commandes_clients WHERE id_commande_client="'.$data['ref_commande_client'].'"';
    								$requete4b = TraiterRequete($sql4b);
    								$data4b = mysql_fetch_array($requete4b);
    								$_SESSION['livraison_commande'][$indexLigneCourante]=$data4b['livraison_commande'];
    								if($_SESSION['livraison_commande'][$indexLigneCourante]==1)
    								{
    									echo 'checked="checked"';
    								}
    								else
    								{
    									echo'';
    								}
    							}
    							echo'/></td>';
    							echo '</tr>';
    							$indexLigneCourante++;
     
    					}
    					else
    					{
    						echo '<tr>';
    						echo '<td class="produits"></td><td class="produits"></td><td class="produits"></td><td class="produits"></td><td class="produits">'.$data['ref_produit'].'</td><td class="produits">'.$data['quantite_produit_commande'].'</td><td class="produits"></td><td class="produits"></td><td class="produits"></td><td class="produits"></td>';
    						echo '</tr>';
    					}
    					$b=$data['ref_commande_client'];
    				}
    				echo'</tbody>
    					 </table>';
    				echo'<input name="valider" type="submit" value="Valider" />
    					 </form>';	 
    			}
    		}mysql_close($connection);	
    }
    ?>

  9. #9
    Nouveau membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mai 2012
    Messages
    42
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Mai 2012
    Messages : 42
    Points : 29
    Points
    29
    Par défaut
    Oops, j'avais oublié de mettre ce post en résolu...
    Je laisse le code au cas où qqn aurait suivi.
    Merci encore Fench, tu m'as bien aidé sur ce coup.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
     
    echo '<td class="produits2">'.$data['prenom_user'].'</td><td class="produits2">'.$data['nom_user'].'</td><td class="produits2">'.$data['adresse_user'].'</td><td class="produits2">'.$data['tel_user'].'</td><td class="produits2">'.$data['ref_produit'].'</td><td class="produits2">'.$data['quantite_produit_commande'].'</td><td class="produits2">'.$data['ref_commande_client'].'</td><td class="produits2">'.$data2['pchtva'].' €</td>
    <td class="produits2">
    <input type="checkbox" name="preparation[]" value="" ';
    if(isset($_POST['valider']) && isset($_POST['preparation'][$indexLigneCourante]))
    {
    	$sql3='UPDATE commandes_clients SET preparation_commande="1" WHERE id_commande_client="'.$data['ref_commande_client'].'"';
    	$requete3 = TraiterRequete($sql3);
    	$sql3b='SELECT preparation_commande FROM commandes_clients WHERE id_commande_client="'.$data['ref_commande_client'].'"';
    	$requete3b = TraiterRequete($sql3b);
    	$data3b = mysql_fetch_array($requete3b);
    	$_SESSION['preparation_commande'][$indexLigneCourante]=$data3b['preparation_commande'];
    	if($_SESSION['preparation_commande'][$indexLigneCourante]==1)
    	{
    		echo 'checked="checked"';
    	}
    	else
    	{
    		echo'';
    	}
    }
    else if(isset($_SESSION['preparation_commande'][$indexLigneCourante]) && $_SESSION['preparation_commande'][$indexLigneCourante]==1)
    {
    	echo 'checked="checked"';
    }
    echo'/></td>';

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. comment jongler garder le meme chekbox apres un destroycomponent
    Par moustaf_26 dans le forum Composants VCL
    Réponses: 3
    Dernier message: 25/09/2011, 12h09
  2. garder un FIFO ouvert en lecture
    Par OuiOui dans le forum Réseau
    Réponses: 4
    Dernier message: 05/01/2003, 19h24
  3. checking de connexion
    Par JEG dans le forum Développement
    Réponses: 4
    Dernier message: 09/10/2002, 13h36
  4. [propriétés]Option Checked
    Par psl dans le forum Composants VCL
    Réponses: 6
    Dernier message: 22/08/2002, 08h07
  5. Check Url pour savoir si erreur 404 ou si le site existe
    Par Clément[Delphi] dans le forum Composants VCL
    Réponses: 2
    Dernier message: 07/08/2002, 13h49

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo