[php] delete from

Résolu
laurent75014 Messages postés 12 Date d'inscription   Statut Membre Dernière intervention   -  
 rasstal -
Bonjour,

Je souhaite supprimer un a un les elements d'une table.
J'ai créé un tableau, j'aimerais qu'il y ait en face de chaque ligne un bouton "DELETE" qui ne delete que la ligne a laquelle il fait reference.

J'ai un debut de code comme cela:

$id_connect=mysql_connect('sql.free.fr','login','pass');
mysql_select_db('toto',$id_connect);


$supprimer="DELETE FROM regicdn WHERE id=".$_POST['id_toto'].;
mysql_query($supprimer, $id_connect) or die(mysql_error());

$tab_result=mysql_query("SELECT * FROM toto order by debut_toto DESC", $id_connect);

while ($ligne=mysql_fetch_array ($tab_result,MYSQL_ASSOC)){
echo '<TR><TD width="7%">'.$ligne['debut_regie'].'</TD><TD width="65%">'.$ligne['descript_toto'].'</TD><TD width="7%">'.$ligne['prenom_toto'].'</TD><TD width="7%">'.$ligne['fin_toto'].'</TD><TD width="3%">'.$ligne['gravit_toto'].'</TD><TD width="3%">'.$ligne['premium_toto'].'</TD><TD width="8%">'.$ligne['nom_toto'].'</TD><TD width="3%">'.$ligne['supp_ligne'].'</td></TR>';
}
mysql_close($id_connect);


Sur la derniere ligne du tableau, je ne sais pas quoi mettre.
Si quelqu'un a une idee, elle sera la bienvenue.
Merci
A voir également:

2 réponses

kij_82 Messages postés 4089 Date d'inscription   Statut Contributeur Dernière intervention   857
 
L'idée est de faire une sorte de formulaire par ligne, avec en fin de ligne le bouton submit du formulaire.
C'est une solution, il y en a d'autre bien plus optimisées mais moins simple techniquement parlant.
Donc pour cette solution, il te faut faire quelque chose dans le genre :
while ($ligne=mysql_fetch_array ($tab_result,MYSQL_ASSOC)){
echo '<TR><form action="fichiercourant.php" method="post"><TD width="7%">'.$ligne['debut_regie'].'</TD><TD width="65%">'.$ligne['descript_toto'].'</TD><TD width="7%">'.$ligne['prenom_toto'].'</TD><TD width="7%">'.$ligne['fin_toto'].'</TD><TD width="3%">'.$ligne['gravit_toto'].'</TD><TD width="3%">'.$ligne['premium_toto'].'</TD><TD width="8%">'.$ligne['nom_toto'].'</TD><TD width="3%">'.$ligne['supp_ligne'].'</td><TD width="??%"><input type="hidden" name="id_toto" value="'.$ligne['id_toto'].'"><input type="submit" value="delete"></TD></form></TR>';
} 


Ainsi tu rappelle à chaque fois ta page courante avec un paramètre caché qui est ton identifiant, et tu le traite comme tu l'as fait dans la premiere partie.

L'idée est là, ca n'a pas été testé donc il est possible que ca bug peut etre mais je ne pense pas.

Bon courage pour la suite.
0
laurent75014 Messages postés 12 Date d'inscription   Statut Membre Dernière intervention   3
 
Merci pour ton aide, ca fonctionne tres bien.
0
rasstal
 
while ($ligne=mysql_fetch_array ($tab_result,MYSQL_ASSOC)){
echo '<TR><form action="fichiercourant.php" method="post"><TD width="7%">'.$ligne['debut_regie'].'</TD><TD width="65%">'.$ligne['descript_toto'].'</TD><TD width="7%">'.$ligne['prenom_toto'].'</TD><TD width="7%">'.$ligne['fin_toto'].'</TD><TD width="3%">'.$ligne['gravit_toto'].'</TD><TD width="3%">'.$ligne['premium_toto'].'</TD><TD width="8%">'.$ligne['nom_toto'].'</TD><TD width="3%">'.$ligne['supp_ligne'].'</td><TD width="??%"><input type="hidden" name="id_toto" value="'.$ligne['id_toto'].'"><input type="submit" value="delete"></TD></form></TR>';
}
0