|
|
|
|
Bonjour
Voila j'ai ecrit le code suivant.
J'ai un tableau avec un certain nombre de colonne. Dont une pour modifier.
Voici le code et ensuite ma question :
<?php
require_once ("Acces_BDPROJETS.php");
// selectionner la base et la variable du pconnect se trouvant dans le fichier Acces_BDPROJETS.php
@mysql_select_db($database_canalbd, $connexion) or die ("problème dans selection base");
// definir la requête
$query_Recordset1="SELECT * FROM projets1, reporting_mensuel WHERE projets1.Num_projet=reporting_mensuel.Num_projet ORDER BY Nom_du_projet AND Mois ASC";
// excecution de la requête
$Recordset1=mysql_db_query ($database_canalbd,$query_Recordset1) or die("Erreur dans la requête");
$row_Recordset1=mysql_fetch_assoc($Recordset1);// ici on rapatrie toutes les lignes de la base
// dans un tableau row_Recordset1
?>
<body bgcolor="#CCCCCC" background="">
<table width="67%" border="1" align="center" bgcolor="#CCCCCC">
<tr>
<td height="23">
<div align="center"><font color="#CC0000"><strong>CONSULTATION DES PROJETS</strong></font></div></td>
</tr>
</table>
<br>
<form name="form1" method="get" action="visu_base.php">
<table width="100%" border="1" align="center">
<tr bgcolor="#FF99FF">
<td width="8%"><div align="center">Id_Projet</div></td>
<td width="6%"><div align="center">Num Projet</div></td>
<td width="12%"><div align="center">Nom Projet</div></td>
<td width="15%"><div align="center">Description</div></td>
<td width="5%"><div align="center">Date</div></td>
<td width="16%"><div align="center">Reporting</div></td>
<td width="17%" bgcolor="#00FFFF"><div align="center">Modifier un projet</div></td>
</tr>
<tr bgcolor="#FF99FF">
<td colspan="6"> </td>
<td bgcolor="#00FFFF"><div align="center">
<input name="modif" type="checkbox" value="">
</div></td>
<tr bgcolor="#FF99FF">
<td colspan="8"><input type="submit" name="Submit" value="Valider"> </td>
</tr>
<?php
$color="66CCFF";
while ($record = mysql_fetch_array($Recordset1))
{
//$tableau .= "<tr bgcolor=#".$color.">";
$tableau .= "<td width=\"6%\" >".$record['Id_projet']."</td>";
$tableau .= "<td width=\"5%\" >".$record['Num_projet']."</td>";
$tableau .= "<td width=\"26%\">".$record['Nom_du_Projet']."</td>";
$tableau .= "<td width=\"28%\">".$record['Description_du_Projet']."</td>";
$tableau .= "<td width=\"5%\">".$record['Mois']."</td>";
$tableau .= "<td width=\"28%\">".$record['Reporting']."</td>
<td input name="modif " type="checkbox" value =""</td></tr>";
}
echo $tableau;
?>
</table>
mysql_close($connexion);
?>
</table>
</form>
</body>
Bsr,
<html>
<head>
<title>Page A</title>
</head>
<body>
<form action="checkbox2.php" method="POST">
<table border=1>
<tr><td>Projet</td><td>Modifier des projets</td><td>Modifier un projet</td></tr>
<?php
$tableau="";
for ($i=0; $i <=10; $i++)
{
$tableau .= '<tr><td>Projet '.$i.'</td>';
$tableau .= '<td align="center"><input type="checkbox" name="modif[]" value="'.$i.'"></td>';
$tableau .= '<td align="center"><input type="radio" name="choix" value="'.$i.'"></td></tr>';
}
echo $tableau;
?>
</table>
<input type="submit" value="Ok">
</form>
</body>
</html>
qui appelle la page checkbox2.php <html> <head> <title>Page B</title> </head> <body> Résultat de la sélection :<br /> <?php
$modif=$_POST["modif"];
for ($i=0; $i <count($modif); $i++)
{
echo "modif[".$i."]=".$modif[$i]."<br />";
}
echo "choix=".$_POST["choix"];
?>
</body>
</html>
J'ai mis 2 colonnes : 1 avec des checkboxes une autre avec des radioboxes (ce qui me semble qd même plus logique si tu modifies un projet à la fois ...) L'astuce pour les checkboxes consistent à donner toujours le même nom sous la forme : name="modif[]" De cette façon PHP récupère un tableau de 1 élément si tu coches 1 options, de 2 éléments si tu coches 2 options etc ... Pour les radioboxes il suffit de donner le même nom Evidemment il faut penser à donner une valeur différente à chaque checkbox /radiobox sinon on ne récupère rien. Dans l'exemple j'ai mis value="'.$i.'" mais remplace la valeur par l'ID de ton projet : value='".$record['Id_projet'].'" Je suppose que ton ID est unique bien sûr Et voilà @+ PhP [Push the button,Don't push the . button,Trip the station,Change the channel] |
Répondre à Rebuffat
|