Problème de pagination

mirakanto -  
arthezius Messages postés 3538 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,
Je souhaite avoir votre aide à propos de mon pagination avec php et mysql. La vérité c'est que je ne sais pas comment ajouter mon code pour faire la pagination simple avec un lien suivant: voici mon code:

<?php
// print_r($_POST);
require_once 'config.php';

$query = "SELECT * FROM membres";

$filtre = array();

if(isset($_POST["nom"]) && $_POST["nom"] != "")
$filtre[] = sprintf("'nom' LIKE '%s' OR 'prenom' LIKE '%s'", "%".$_POST["nom"]."%", "%".$_POST["nom"]."%");
if(isset($_POST["civilite"]) && $_POST["civilite"] != "")
$filtre[] = sprintf("'civilite' = '%s'", $_POST["civilite"]);

if(count($filtre) != 0)
$query = $query." WHERE ".implode(" AND ", $filtre);

if(isset($_GET["page"]))
$page = $_GET["page"];
else
$page = 0;

$par_page = 2;

$query = sprintf("%s LIMIT %d, %d", $query, $page*$par_page, $par_page);

//echo $query;

$res = mysql_query($query) OR die (mysql_error());

//$par_page = mysql_num_rows($query);

?>
<script language="javascript">
function confirme(){
var confirmation = confirm("Voulez vous vraiment supprimer cette personne?");
if(confirmation){
return true;
}
return false;
}
</script>
<form method="post" action="">
<table cellpadding="0" cellspacing="0">
<tr><td><a href="index.php">Formulaire</td></tr>
<tr align="left">
<td>Rechercher par nom: </td>
<td><input type="text" name="nom" id="filtre" value="<?php if(isset($_POST["nom"])) echo $_POST["nom"]; ?>"></td>
<td><input type="submit" value="Chercher"></td>
</tr>
<td>Rechercher tous les: </td>
<td><select name="civilite">
<option value="" <?php if(isset($_POST["civilite"]) && $_POST["civilite"] == ""){ echo 'selected="selected"'; } ?>>Tous</option>
<option value="Mr" <?php if(isset($_POST["civilite"]) && $_POST["civilite"] == "Mr"){ echo 'selected="selected"'; } ?>>Mr</option>
<option value="Mme" <?php if(isset($_POST["civilite"]) && $_POST["civilite"] == "Mme"){ echo 'selected="selected"'; } ?>>Mme</option>
<option value="Mlle" <?php if(isset($_POST["civilite"]) && $_POST["civilite"] == "Mlle"){ echo 'selected="selected"';} ?>>Mlle</option>
</select></td>
</tr>
</table>
</form>
<table width="100%" border="1">
<?php if(isset($_GET["msg"])) :?>
<tr>
<td colspan="10">
<?php echo $_GET["msg"]; ?>
</td>
</tr>
<?php endif ?>
<tr>
<th width="2">Civilité</th>
<th width="50" align="center">Nom</th>
<th width="20" align="center">Prénom</th>
<th width="20" align="center">Date de naissance</th>
<th width="20" align="center">Profession</th>
<th width="20" align="center">Ville</th>
<th width="3" align="center">Code Postal</th>
<th width="20" align="center">Téléphone</th>
<th width="5" align="center">E-mail</th>
<th width="5" align="center">Action</th>
</tr>
<?php
while($data = mysql_fetch_array($res)){
?>

<tr valign="top">
<td align="center" class="td1"><?php echo $data["civilite"];?></td>
<td align="center" class="td2"><strong><?php echo $data["nom"]; ?></strong></td>
<td align="center" class="td3"><i><?php echo $data["prenom"]; ?></i></td>
<td align="center" class="td4"><?php echo $data["date_nais"]; ?></td>
<td align="center" class="td5"><?php echo $data["profession"]; ?></a></td>
<td align="center" class="td6"><?php echo $data["ville"]; ?></td>
<td align="center" class="td7"><?php echo $data["cp"]; ?></td>
<td align="center" class="td8"><?php echo $data["telephone"]; ?></td>
<td align="center" class="td9"><?php echo $data["email"]; ?></td>
<td align="center" class="td8"><a href="maj.php?id_membre=<?php echo $data["id_membre"]; ?>">Editer</a>   
<a
href="supprime.php?id_membre=<?php echo $data["id_membre"]; ?>"
onclick="return confirme();"
>
Supprimer
</a></td>
</td>
</tr>
<?php } ?>
</table>
<a href="liste.php?<?php if(isset($_GET["page"])) echo $par; ?> ">suivant</a>

J'éspère avoir une meilleure réponse venant de vous et je vous remercie d'avance!

cordialement!
mirakanto

1 réponse

arthezius Messages postés 3538 Date d'inscription   Statut Membre Dernière intervention   475
 
Personnellement j'utilise ce script: http://www.lephpfacile.com/howto/6-comment-faire-un-affichage-page-par-page-en-php
Tu peux l'étudier et l'adapter à ton code. Il est pas compliqué.
0
mirakanto
 
Merci quand même pour ton aide arthezius mais j'ai déjà essayer mais je n'y arrive pas!
Merci beaucoup!
0
arthezius Messages postés 3538 Date d'inscription   Statut Membre Dernière intervention   475
 
Si tu as essayé, tu as donc modifié ton code à partir de celui fournis sur mon lien.
Peux-tu nous mettre ton code pour qu'on puisse t'aider à le modifier?
0