Checkbox
thomason
Messages postés
93
Statut
Membre
-
dreamfeeder Messages postés 253 Statut Membre -
dreamfeeder Messages postés 253 Statut Membre -
bonsoir à tous,
jè un gros problème , en fait je recupére tous les enregistrement d'une table et j'affiche dans un tableau exactement comme c'est enregistré dans la base.je problème c que je veux mettre devant chaque enregistrement recupéré un checkbox qui prend en compte toute la ligne de mon enregistrement.
et ensuite je vais mettre un selected apres le tableau avec les differents statuts.ce qui me permetra de faire ceci lorsque je clique sur le checkbox d'une ligne et je choisi un statut avec mon option select crée apres mon tableau et je valide , on la modification du statut dans la bd.
voici mon code qui récupère les enregistrements:
<?php
$bdd = "projet";
$host= "localhost";
$user= "root";
$pass= "";
$tabReponse='';
if (mysql_connect($host,$user,$pass)){
//echo'connexion';
}
else {
echo '"Impossible de se connecter à la base de données"'.mysql_error(); }
if(mysql_select_db('projet')){
echo'';
}
else{
echo'"erreur"'.mysql_error();
}
$requete= "SELECT *FROM demande ";
$resultat = mysql_query($requete) or die ('erreur '.$requete.' '.mysql_error());
if ($tabreponse = mysql_num_rows( $resultat )){;
?>
<p style="color:#333333" align="center" ><em><strong><span class="Style6">utilisateurs</span>:</strong></em></p>
<table width="859" border="0" align="center" >
<tr bgcolor="#0099FF" onMouseOut="javascript:this.style.background='#0099FF'" onMouseOver="javascript:this.style.background='#99CCFF'">
<td width="22"></td>
<td width="93" height="33"><div align="center"><em><strong>Numéro</strong></em></div></td>
<td width="91"><div align="center"><em><strong>Date</strong></em></div></td>
<td width="96"><div align="center"><em><strong>Heure</strong></em></div></td>
<td width="138"><div align="center"><em><strong>Opérateur</strong></em></div></td>
<td width="121"><div align="center"><em><strong>Statut</strong></em></div></td>
<td width="131"><div align="center"><em><strong>Montant</strong></em></div></td>
<td width="133"><div align="center"><em><strong>Compte</strong></em></div></td>
</tr>
</table>
<?php
while($tabReponse = mysql_fetch_array( $resultat )){?>
<table width="862" border="0" align="center" bgcolor="#FFFFCC" >
<tr onMouseOut="javascript:this.style.background='#FFFFCC'" onMouseOver="javascript:this.style.background='#CCCCCC'" >
<td width="24" align="left"><input type="checkbox" name="selected" value="<?php $tabreponse[0]?>"></td>
<td width="92" align="center" style="font-weight:bold;color:#444444" ><?php echo $tabReponse['numero_demande']; ?></td>
<td width="90" align="center" style="font-weight:bold;"><?php echo $tabReponse[ 'date_soumission'];?></td>
<td width="97" align="center" style="font-weight:bold;color:#444444"><?php echo $tabReponse['heure'];?></td>
<td width="139" align="center" style="font-weight:bold;"><?php echo $tabReponse['login'];?></td>
<td width="121" align="center"style="font-weight:bold;color:#444444"><?php echo $tabReponse['statut'];?></td>
<td width="132" align="center"style="font-weight:bold;"><?php echo $tabReponse['montant'];?></td>
<td width="133" align="center"style="font-weight:bold;color:#444444"><?php echo $tabReponse['compte'];?></td>
</tr>
</table>
<?php
}
}
?>
merci d'avance
jè un gros problème , en fait je recupére tous les enregistrement d'une table et j'affiche dans un tableau exactement comme c'est enregistré dans la base.je problème c que je veux mettre devant chaque enregistrement recupéré un checkbox qui prend en compte toute la ligne de mon enregistrement.
et ensuite je vais mettre un selected apres le tableau avec les differents statuts.ce qui me permetra de faire ceci lorsque je clique sur le checkbox d'une ligne et je choisi un statut avec mon option select crée apres mon tableau et je valide , on la modification du statut dans la bd.
voici mon code qui récupère les enregistrements:
<?php
$bdd = "projet";
$host= "localhost";
$user= "root";
$pass= "";
$tabReponse='';
if (mysql_connect($host,$user,$pass)){
//echo'connexion';
}
else {
echo '"Impossible de se connecter à la base de données"'.mysql_error(); }
if(mysql_select_db('projet')){
echo'';
}
else{
echo'"erreur"'.mysql_error();
}
$requete= "SELECT *FROM demande ";
$resultat = mysql_query($requete) or die ('erreur '.$requete.' '.mysql_error());
if ($tabreponse = mysql_num_rows( $resultat )){;
?>
<p style="color:#333333" align="center" ><em><strong><span class="Style6">utilisateurs</span>:</strong></em></p>
<table width="859" border="0" align="center" >
<tr bgcolor="#0099FF" onMouseOut="javascript:this.style.background='#0099FF'" onMouseOver="javascript:this.style.background='#99CCFF'">
<td width="22"></td>
<td width="93" height="33"><div align="center"><em><strong>Numéro</strong></em></div></td>
<td width="91"><div align="center"><em><strong>Date</strong></em></div></td>
<td width="96"><div align="center"><em><strong>Heure</strong></em></div></td>
<td width="138"><div align="center"><em><strong>Opérateur</strong></em></div></td>
<td width="121"><div align="center"><em><strong>Statut</strong></em></div></td>
<td width="131"><div align="center"><em><strong>Montant</strong></em></div></td>
<td width="133"><div align="center"><em><strong>Compte</strong></em></div></td>
</tr>
</table>
<?php
while($tabReponse = mysql_fetch_array( $resultat )){?>
<table width="862" border="0" align="center" bgcolor="#FFFFCC" >
<tr onMouseOut="javascript:this.style.background='#FFFFCC'" onMouseOver="javascript:this.style.background='#CCCCCC'" >
<td width="24" align="left"><input type="checkbox" name="selected" value="<?php $tabreponse[0]?>"></td>
<td width="92" align="center" style="font-weight:bold;color:#444444" ><?php echo $tabReponse['numero_demande']; ?></td>
<td width="90" align="center" style="font-weight:bold;"><?php echo $tabReponse[ 'date_soumission'];?></td>
<td width="97" align="center" style="font-weight:bold;color:#444444"><?php echo $tabReponse['heure'];?></td>
<td width="139" align="center" style="font-weight:bold;"><?php echo $tabReponse['login'];?></td>
<td width="121" align="center"style="font-weight:bold;color:#444444"><?php echo $tabReponse['statut'];?></td>
<td width="132" align="center"style="font-weight:bold;"><?php echo $tabReponse['montant'];?></td>
<td width="133" align="center"style="font-weight:bold;color:#444444"><?php echo $tabReponse['compte'];?></td>
</tr>
</table>
<?php
}
}
?>
merci d'avance
A voir également:
- Checkbox
- Html checkbox value 1 or 0 ✓ - Forum PHP
- [VBA] liste déroulante de checkbox dynamique - Forum VB / VBA
- Macro pr copier des cellule si checkbox coché - Forum Programmation
- Code VBA powerpoint checkbox avec condition et renvoi - Forum Powerpoint
- VBA - Formulaire avec checkbox ou listbox à choix multiple - Forum Excel
1 réponse
bonjour,
pour envoyer ton formulaire, il te faut une balise <form action="" method="post"></form> avec l'attribut action qui pointe soit vers la meme page si tu veux mettre ton code de modification dans cette meme page soit vers une autre page si tu veux separée ce code, et un <input type="submit'> afin d'envoyer ce formulaire.
il faut qe tu remplaces:
<input type="checkbox" name="selected" value="<?php $tabreponse[0]?>">
par
<input type="checkbox" name="<?php $tabreponse[0]?>">
ensuite pour le code tu fais une boucle avec a l'interieur une requete UPDATE qui modifie le statut pour chaque id renvoyé par le formulaire genre:
<?
$statut=$_POST['le_nom_de_ton_champ_select'];
foreach($_POST as $key=>$val)
{
if($val=="on")
{
$requete="UPDATE demande SET statut='$statut' WHERE ID='$key'";
$resultat = mysql_query($requete) or die ('erreur '.$requete.' '.mysql_error());
}
}
?>
cordialement, dreamfeeder.
pour envoyer ton formulaire, il te faut une balise <form action="" method="post"></form> avec l'attribut action qui pointe soit vers la meme page si tu veux mettre ton code de modification dans cette meme page soit vers une autre page si tu veux separée ce code, et un <input type="submit'> afin d'envoyer ce formulaire.
il faut qe tu remplaces:
<input type="checkbox" name="selected" value="<?php $tabreponse[0]?>">
par
<input type="checkbox" name="<?php $tabreponse[0]?>">
ensuite pour le code tu fais une boucle avec a l'interieur une requete UPDATE qui modifie le statut pour chaque id renvoyé par le formulaire genre:
<?
$statut=$_POST['le_nom_de_ton_champ_select'];
foreach($_POST as $key=>$val)
{
if($val=="on")
{
$requete="UPDATE demande SET statut='$statut' WHERE ID='$key'";
$resultat = mysql_query($requete) or die ('erreur '.$requete.' '.mysql_error());
}
}
?>
cordialement, dreamfeeder.