[php] cocher toutes les cases

Résolu
neo2099 Messages postés 164 Date d'inscription   Statut Membre Dernière intervention   -  
Scalpweb Messages postés 1467 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

Voila je me suis creer une page ou je peux voir tous les messages que mes utilisateurs s'envoie sur mon sites pour controler qui n'y ai pas d'abus. Je peux en supprimés grace a des checkbox et au lieu de les supprimés une a une je voudrais pouvoir les supprimés toutes d'un coup j'ai trouver plusieurs code mais comme j'utilise des variables dans mes checkbox je galere un peu.
Pouvais-vous m'aidez???
Voici un bout de mon code :

if($_GET['page'] == "mp")//ici c'est cette partie qui nous interesse
{
echo '<form action="traitementsup.php" method="POST">';//la c'est la page qui permet de supprimés les messages
$mp = mysql_query("select * from mail order by id");//la requete pour aller chercher les messages
$i=0;//i est a 0
echo '<table border="2">';
echo '<tr>';
echo '<td width="50" height="50">Supprimées</td>';
echo '<td width="50" height="50">ID</td>';
echo '<td width="50" height="50">Pseudo</td>';
echo '<td width="50" height="50">Titre</td>';
echo '<td width="500" height="50">Message</td>';
echo '<td width="50" height="50">Destinataire</td>';
echo '<td width="50" height="50">Date</td>';


while($msgper=mysql_fetch_array($mp))//je restitue toutes les infos
{
echo '</tr><tr>';
echo "<td width='50' height='50'><center><input type='checkbox' name='$msgper[0]' value='sup'>Supprimées</td>";
echo '<td width="50" height="50"><center>' .$msgper[$i]. '</td>';
echo '<td width="50" height="50"><center><a href="mail.php?page=' .$msgper[$i+1]. '">' .$msgper[$i+1]. '</td>';
echo '<td width="50" height="50"><center>' .$msgper[$i+2]. '</td>';
echo '<td width="50" height="50"><center>' .$msgper[$i+3]. '</a></td>';
echo '<td width="50" height="50"><center>' .$msgper[$i+4]. '</td>';
echo '<td width="50" height="50"><center>' .$msgper[$i+5]. '</td>';

echo '</tr>';


}
echo '</table>';
echo '<br>';
echo '<input type="submit" value="Validez"><br>';
}

}
?>
voila si vous pouviez m'aider
Merci d'avance

9 réponses

Scalpweb Messages postés 1467 Date d'inscription   Statut Membre Dernière intervention   43
 
Si j'ai bien compris tu veux pouvoir avoir un bouton qui te permet de cocher toutes les checkbox de ton tableau c'est ça ?

Pour cela, ce n'est pas du php, c'est du javascript.

Le seul truc que tu pourrais éventuellement faire en php, c'est rajouter "checked=checked" à l'intérieur de ta balise input pour que, d'office, elles soient toutes cochées mais je pense pas que ce soit ça que tu veuilles faire...

Je peux te donner le code javascript, mais j'aurais pour cela besoin de voir ton code html produit par le code php (juste le tableau).
0
neo2099 Messages postés 164 Date d'inscription   Statut Membre Dernière intervention   12
 
re voici le fichier en html

<HTML>
<HEAD>
</head>
<body bgcolor="black" style="color: #FFFFFF">
<center>
<h1>*********<h1>
<h3>Partie Administrateur</h3><br>

<form action="traitementsup.php" method="POST">
<table border="2">
<tr>
<td width="50" height="50">Supprimées</td>
<td width="50" height="50">ID</td>
<td width="50" height="50">Pseudo</td>
<td width="50" height="50">Titre</td>
<td width="500" height="50">Message</td>
<td width="50" height="50">Destinataire</td>
<td width="50" height="50">Date</td></tr>
<tr>
<td width='50' height='50'><center><input type='checkbox' name='136' value='sup'>Supprimées</td>
<td width="50" height="50"><center>136</td>
<td width="50" height="50"><center><a href="mail.php?page=Luke">Luke</td></a>
<td width="50" height="50"><center></td>
<td width="50" height="50"><center>le message</td>
<td width="50" height="50"><center>destinataire</td>
<td width="50" height="50"><center>2008-01-28 10:21:02</td
></tr></tr>
<tr>
<td width='50' height='50'><center>
<input type='checkbox' name='137' value='sup'>Supprimées</td>
<td width="50" height="50"><center>137</td><td width="50" height="50"><center><a href="mail.php?page=Luke">Luke</td></a>
<td width="50" height="50"><center></td>
<td width="50" height="50"><center>

message

</td><td width="50" height="50"><center>kaser</td><td width="50" height="50"><center>2008-01-28 10:22:25</td>
</table>
<br><input type="submit" value="Validez"><br>

voila en gros c'est sa mon fichier
0
Scalpweb Messages postés 1467 Date d'inscription   Statut Membre Dernière intervention   43
 
Alors dans ton code php, commences pas donner un nom à ton form :
echo '<form action="traitementsup.php" method="POST" name="myForm">'


Ensuite, dans on modifie un peu ta boucle while :

$jScript = "";
while($msgper=mysql_fetch_array($mp))//je restitue toutes les infos
{
echo '</tr><tr>';
echo "<td width='50' height='50'><center><input type='checkbox' id='ch$msgper[0]' name='ch$msgper[0]' value='sup'>Supprimées</td>";
echo '<td width="50" height="50"><center>' .$msgper[$i]. '</td>';
echo '<td width="50" height="50"><center><a href="mail.php?page=' .$msgper[$i+1]. '">' .$msgper[$i+1]. '</td>';
echo '<td width="50" height="50"><center>' .$msgper[$i+2]. '</td>';
echo '<td width="50" height="50"><center>' .$msgper[$i+3]. '</a></td>';
echo '<td width="50" height="50"><center>' .$msgper[$i+4]. '</td>';
echo '<td width="50" height="50"><center>' .$msgper[$i+5]. '</td>';
echo '</tr>';
$jScript = $jScript . "document.myForm.ch".$msgper[0].".checked=true;\n";
} 

echo "<script type=\"text/javascript\">\nfunction Coche(){\n".$jScript."}</script>";




Puis, plus bas dans ta page, tu fais un lien du style :
<input type="button" onclick="javascript:Coche();" value="Tout cocher" />


Voilà,
@+
0
neo2099 Messages postés 164 Date d'inscription   Statut Membre Dernière intervention   12
 
ouai sa marche tout se coche mais maintenant je ne peux plus rien supprimés mdr
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Scalpweb Messages postés 1467 Date d'inscription   Statut Membre Dernière intervention   43
 
ah oui autant pour moi !

Voilà le vrai code de ta boucle while,j'avais oublié de rechanger un truc :

$jScript = "";
while($msgper=mysql_fetch_array($mp))//je restitue toutes les infos
{
echo '</tr><tr>';
echo "<td width='50' height='50'><center><input type='checkbox' id='ch$msgper[0]' name='ch$msgper[0]' value='sup'>Supprimées</td>";
echo '<td width="50" height="50"><center>' .$msgper[$i]. '</td>';
echo '<td width="50" height="50"><center><a href="mail.php?page=' .$msgper[$i+1]. '">' .$msgper[$i+1]. '</td>';
echo '<td width="50" height="50"><center>' .$msgper[$i+2]. '</td>';
echo '<td width="50" height="50"><center>' .$msgper[$i+3]. '</a></td>';
echo '<td width="50" height="50"><center>' .$msgper[$i+4]. '</td>';
echo '<td width="50" height="50"><center>' .$msgper[$i+5]. '</td>';
echo '</tr>';
$jScript = $jScript . "document.myForm.ch".$msgper[0].".checked=true;\n";
} 

echo "<script type=\"text/javascript\">\nfunction Coche(){\n".$jScript."}</script>";


Si ça te ocnvient, bascule le statut de ce post en tant que "Résolu".
0
neo2099 Messages postés 164 Date d'inscription   Statut Membre Dernière intervention   12
 
eeeeuuuu c'est exactement le meme truc que tu m'avais donner il y a rien de changer????? et ca ne supprime plus et je vois pas du tout ou est l'erreur
0
Scalpweb Messages postés 1467 Date d'inscription   Statut Membre Dernière intervention   43
 
Je suis idiot...

Voilà :

$jScript = "";
while($msgper=mysql_fetch_array($mp))//je restitue toutes les infos
{
echo '</tr><tr>';
echo "<td width='50' height='50'><center><input type='checkbox' id='ch$msgper[0]' name='$msgper[0]' value='sup'>Supprimées</td>";
echo '<td width="50" height="50"><center>' .$msgper[$i]. '</td>';
echo '<td width="50" height="50"><center><a href="mail.php?page=' .$msgper[$i+1]. '">' .$msgper[$i+1]. '</td>';
echo '<td width="50" height="50"><center>' .$msgper[$i+2]. '</td>';
echo '<td width="50" height="50"><center>' .$msgper[$i+3]. '</a></td>';
echo '<td width="50" height="50"><center>' .$msgper[$i+4]. '</td>';
echo '<td width="50" height="50"><center>' .$msgper[$i+5]. '</td>';
echo '</tr>';
$jScript = $jScript . "document.myForm.ch".$msgper[0].".checked=true;\n";
} 

echo "<script type=\"text/javascript\">\nfunction Coche(){\n".$jScript."}</script>";


Y'a juste un tout petit truc de changé, dans la balise <input>.
0
neo2099 Messages postés 164 Date d'inscription   Statut Membre Dernière intervention   12
 
Cette fois c'est bon un grand merci sa m'avance un peu dans mon boulot, tous sa pour un site de jeu pfiouuuuuuffff
0
Scalpweb Messages postés 1467 Date d'inscription   Statut Membre Dernière intervention   43
 
De rien,

@+
0