[PHP]checkbox /plusieurs pages

Fermé
theflagada Messages postés 57 Date d'inscription mercredi 14 mars 2007 Statut Membre Dernière intervention 27 octobre 2009 - 1 oct. 2007 à 10:59
theflagada Messages postés 57 Date d'inscription mercredi 14 mars 2007 Statut Membre Dernière intervention 27 octobre 2009 - 1 oct. 2007 à 11:27
Bonjour,
Voici mon petit souci: je fais une boucle pour recuperer les infos de ma table et j affiche le tout par page de 200 resultats (j en ai 8000 en tout). Bref jusque la tout va bien... par contre je souhaite mettre une checkbox en face de chaque ligne sur ma pag epour pouvoir selectionner toutes les lignes, mais pas seulement celles de la page en cours, toutes les 8000 lignes. Je ne sais pas comment faire cela. si quelqu'un peut m'aider, merci d'avance.
A voir également:

4 réponses

Bonjour,

As tu essayé d'utiliser une variable de session, par exemple un booléen, indiquant si la checkbox qui sélectionne tout est cochée ou pas, et ensuite un test sur le variable pour effectuer le traitement de ton choix.
0
theflagada Messages postés 57 Date d'inscription mercredi 14 mars 2007 Statut Membre Dernière intervention 27 octobre 2009 4
1 oct. 2007 à 11:20
j'ai peur de ne pas bien comprendre comment faire cela...

en gros voici mon code:

<?
// DÉTERMINE LE NOMBRE DE LIGNE À AFFICHER

$limit_par_page = 200;

if(isset($_GET['page'])){
$page = $_GET['page'];
$page = $page - 1;
}
else{
$page = 0;
}

$from = $page * $limit_par_page;



$request = "SELECT DISTINCT Dest,country,code FROM currentprices ORDER BY Dest LIMIT $from,$limit_par_page ";

if ($result = mysql_query($request)){
if(mysql_num_rows($result)!=0){


while($reult=mysql_fetch_assoc($result)){
$cpt++;
$group=$reult['Dest'];
list($pays,$a,$b,$c)=split("[\n\r\t ]+", $group);
$twowords=$pays." ".$a;
$group2=$reult['country'];
$group3=$reult['code'];

if(isset($_POST['all']) && in_array($_POST['all'],$postactions)){
$checked_2="checked";

}

else if(isset($_POST['any']) && in_array($_POST['any'],$postactions)){
$checked_2="";

}

$lo .="<tr >
<td style=\"\"> </td><td style=\"padding:5px;border:1px solid grey\">".$group."</td>

<td style=\"text-align:center;border:1px solid grey\">".$group2."</td>
<td style=\"text-align:left;padding:5px 5px 5px 10px;border:1px solid grey\">".$group3."</td>
<td colspan=\"2\" style=\"text-align:center;border:1px solid grey\"><input type=\"checkbox\" name=\"'br".$cpt."'\" value=\"Submit\" ".$checked_2."/></td>
</tr>";



}

//echo $OUT;
}else $report='<br/>You have no data for this company !';
}else{
echo "Error while creating the file. Please try again later.";
}





$sql2 = mysql_query("SELECT COUNT(*) AS nb_msg FROM prices" );
$donnees2 = mysql_fetch_array($sql2);
$nb_msg = $donnees2['nb_msg'];
$nb_pages = ceil($nb_msg / $limit_par_page);



for($page=1;$page<=$nb_pages;$page++)

{

$echo.="<a href=\"destinations.php?page=$page\">$page </a>";

}

if ($_GET['page']>=11) {

for ($page=1;$page<=1;$page++) {

$eho.="<a href=\"destinations.php?page=$page\">1</a>";
}
for ($page=$_GET['page']-11;$page<$_GET['page']-10;$page++) {

$eho.="<a href=\"destinations.php?page=$page\">...</a>";
}
for ($page=$_GET['page']-10;$page<=$_GET['page']+10;$page++) {

$eho.="<a href=\"destinations.php?page=$page\">$page </a>";

}
for ($page=$_GET['page']+11;$page<$_GET['page']+12;$page++) {

$eho.="<a href=\"destinations.php?page=$page\">...</a>";
}
for ($page=$nb_pages;$page<=$nb_pages;$page++) {

$eho.="<a href=\"destinations.php?page=$page\">$nb_pages</a>";
}



}
else{
for ($page=1;$page<=$_GET['page']+10;$page++) {

$eho.="<a href=\"destinations.php?page=$page\">$page </a>";
}
for ($page=$_GET['page']+11;$page<$_GET['page']+12;$page++) {

$eho.="<a href=\"destinations.php?page=$page\">...</a>";
}

for ($page=$nb_pages;$page<=$nb_pages;$page++) {

$eho.="<a href=\"destinations.php?page=$page\">$nb_pages</a>";
}
}
$OUT="<form method=\"POST\" action=\"\" name=\"plop\" enctype=\"multipart/form-data\">
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"TitleColor\" style=\"FONT-FAMILY: Arial;padding:0;margin:0; width:100%\">
<tr>
<td style=\"vertical-align:middle;padding:1px 0px 1px 3px;margin:1px;border:0px solid #FFFFFF;width:40%;background-color:#aebfce;color:#000000;font-size:11px;\"><img name=\"careful\" style=\"vertical-align:middle;color:#f2f1f1;\" src=\"../pictures/insertprice.png\" alt=\"\">Destinations for <b>".$client."<b> </td>
</tr>
<tr>
<td style=\"height:15px;\"></td>
</tr>

</table>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"TitleColor\" style=\"FONT-FAMILY: Verdana;vertical-align:top; FONT-SIZE: 8pt;width:100%;background-color:#f2f1f1;padding:10px 10px 10px 20px\">
<tr >


</tr >
<tr >

<td style=\"width:15%;\"> </td>
<td style=\"width:25%;\"> </td>
<td style=\"width:15%;\"> </td>



<td style=\"width:7%;vertical-align:bottom;font-weight:bold;padding:0;text-align:center;border:0px solid grey;margin:5px\"><input style=\"font-weight:bold;text-align:center;background-color:#f2f1f1;border:1px solid grey;text-decoration:none;cursor:pointer;\" type=\"submit\" name=\"all\" value=\"All\"></td>
<td style=\"width:7%;vertical-align:bottom;font-weight:bold;padding:0;text-align:center;border:0px solid grey;margin:5px\"><input style=\"font-weight:bold;text-align:center;background-color:#f2f1f1;border:1px solid grey;text-decoration:none;cursor:pointer;\" type=\"submit\" name=\"any\" value=\"None\"></td>
<td style=\"width:16%;\"> </td>


</tr >

<tr >
<td style=\"width:15%;\"> </td>

</tr >
<tr >
<td style=\"\"> </td>

<td style=\"text-align:center;border:1px solid grey;height:20px;background-color:#aebfce;font-weight:bold;\">Destinations (".$NBdests.")</td>
<td style=\"text-align:center;border:1px solid grey;height:20px;background-color:#aebfce;font-weight:bold;\">Country </td>
<td style=\"text-align:center;border:1px solid grey;height:20px;background-color:#aebfce;font-weight:bold;\"> Code</td>
<td colspan=\"2\" style=\"text-align:center;border:1px solid grey;height:20px;background-color:#aebfce;font-weight:bold;\">check</td></tr>

$lo





<tr>

<td colspan=\"6\" style=\"height:60px;padding:0 0 0 100px;width:20%;text-align:right;\"><input type=\"submit\" name=\"act\" value=\"Enter\"><input type=\"hidden\" name=\"modifierentrdee\" value=\"Modifierftions\"></td>
</tr>
<tr >
<td style=\"\"> </td>
<td style=\"width:15%;\" colspan=\"4\">$ho</td>

</tr >
<tr >
<td style=\"\"> </td>
<td style=\"width:15%;\" colspan=\"4\">$eho</td>

</tr >

</table>
</form>
";

echo $OUT;
?>
0
Reivax962 Messages postés 3672 Date d'inscription jeudi 16 juin 2005 Statut Membre Dernière intervention 11 février 2021 1 011
1 oct. 2007 à 11:21
Bonjour,

Autre possibilité, tu crées un champ <input type="hidden"> dont la valeur garde en mémoire tous les id des lignes cochées, séparés par des ;
A chaque fois qu'une case est cochée, tu rajoutes xxx; à sa valeur, quand une case est décochée tu l'enlèves (via une expression rationnelle par exemple).
Comme ça, d'une page à l'autre, il te suffit de transmettre ce champ, ce qui est beaucoup plus simple.

Xavier
0
theflagada Messages postés 57 Date d'inscription mercredi 14 mars 2007 Statut Membre Dernière intervention 27 octobre 2009 4
1 oct. 2007 à 11:27
Je suis desole, le code est un peu sale mais je le nettoi a la fin ... Peut etre que je n ai pas bien concu mon truc; en fait je fais ma requete et quand je clic sur "All" il confere 'checked ' a la checkbox...
0