salut
voila j'utilise un tableau (créé en allant lire une table de ma bdd) et pour chaque enregistrement j'ajoute une checkbox utilisé pour la supression de cet enregistrement.
La requête sql semble bonne mais il se passe rien.
Voici le code de la page principal et ensuite de la page qui s'occupe de supprimer.
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 <form method="post" action="supprimer.php"> <table> <caption>tableau</caption> <thead> <tr> <th>Id</th> <th>Horaire</th> <th>Entreprise</th> <th>Lieu</th> <th>Contact</th> <th>Téléphone</th> <th>Poste</th> <th>Remarque</th> </tr> </thead> <?php $i=1; $j=0; $supprimer[]=""; while($recup = mysql_fetch_array($donnees)) { ?> <tbody> <tr> <td><?php echo $i; ?></td> <td><?php echo $recup['horaire']; ?></td> <td><?php echo $recup['entreprise']; ?></td> <td><?php echo $recup['lieu']; ?></td> <td><?php echo $recup['contact']; ?></td> <td><?php echo $recup['tel']; ?></td> <td><?php echo $recup['poste']; ?></td> <td><?php echo $recup['remarque']; ?></td> <td><input type="checkbox" name="supprimer[]" value="<?php echo$recup['id'];?>" />suppr</td> </tr> </tbody> <?php $i++; } //fin boucle while ?> </table> <p> <input type="submit" /> <input type="reset" /> </p>donc en faisant un var_dump($tab) et un echo $tab[$i][$j]; les valeurs sont bien là.
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 <?php if (isset($_POST['supprimer'])) { mysql_connect("localhost", "root", ""); mysql_select_db("entretiens"); $n[]=""; $i=0; $k=0; $n=count($_POST['supprimer']); //boucle peut etre inutile mais pas moyen d'utiliser $_POST['supprimer'][$i] for($j=0;$j<$n;$j++) { $tab[$j]=$_POST['supprimer']; } //var_dump($tab); //echo "valeur de n: $n "; //echo $tab[0][0]; for($k=0;$k<$n;$k++) { //echo $tab[$i][$j]; mysql_query("DELETE * FROM stage WHERE id='".$tab[$i][$k]."'"); } mysql_close(); echo "ok"; } ?>
La ligne suivante n'est donc pas interprété et je ne comprends pas pourquoi:
mysql_query("DELETE * FROM stage WHERE id='".$tab[$i][$k]."'");
Partager