IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PHP & Base de données Discussion :

Pagination en php


Sujet :

PHP & Base de données

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2011
    Messages
    31
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2011
    Messages : 31
    Points : 13
    Points
    13
    Par défaut Pagination en php
    Bonjour voila mon problème je voudrais faire une pagination sur ma table.
    La requête fonctionne (tester)
    Le problème est que lorsque je mets le code pour la pagination il n'y a que "Page : " qui est afficher sur la page index.php et je ne trouve pas l'erreur


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
     
    <?php
    include('connexion.inc');
    ?>
    <html>
        <head>
          <title>Info-commune</title>
        </head>
      <body>
     
    <?php
      $messagesParPage=15; 
      $retour_total=pg_query('SELECT COUNT(*) AS total FROM communes'); 
      $donnees_total=pg_fetch_assoc($retour_total); 
      $total=$donnees_total['total']; 
     
     
      $nombreDePages=ceil($total/$messagesParPage);
     
      if(isset($_GET['page'])) 
    {
         $pageActuelle=intval($_GET['page']);
     
      if($pageActuelle>$nombreDePages) 
    {
         $pageActuelle=$nombreDePages;
    }
    }
       else 
    {
        $pageActuelle=1;  
    }
     
      $premiereEntree=($pageActuelle-1)*$messagesParPage; 
     
     
      $req = $connexion->prepare("SELECT * FROM communes Where nom like  '$cherchnom%'or  dept='$cherchdep'  or region = '$cherchreg' LIMIT '.$premiereEntree.', '.$messagesParPage.' ");
      $req->execute();
      $req->setFetchMode(PDO::FETCH_ASSOC);
      $Idd = 1;
        while ($affichage = $req->fetchObject()) {                                     
    ?>
     
    <table>
      <thead>
        <tr>
          <td><font size="2" ><b>N&deg;</b></font></td>
          <td><font size="2" ><b>Nom</b></font></td>
          <td><font size="2" ><b>Population</b></font></td>
          <td><font size="2" ><b>Departement</b></font></td>
          <td><font size="2" ><b>N&deg; commune</b></font></td>
          <td><font size="2" ><b>R&eacute;gion</b></font></td>
         </tr>
        </thead>
          <tr>
    	<td><?php echo $Idd ?></td>
            <td><?php echo '<a href="recherche.php?nom_ascii_maj='.$affichage->nom_ascii_maj.'&region='.$affichage->region.'&population='.$affichage->population.'&departement='.$affichage->dept ?>"><?php echo $affichage->nom_ascii_maj ?></a></td>
            <td><?php echo $affichage->population ?></td>
            <td><?php echo $affichage->dept ?></td>
            <td><?php echo $affichage->comm ?></td>
            <td><?php echo $affichage->region ?></td>
           </tr>
    <?php
      $Idd = $Idd + 1;
    }
    ?>
    </table>
     
    <?php
      echo '<p align="center">Page : '; 
      for($i=1; $i<=$nombreDePages; $i++)
    {
      if($i==$pageActuelle) 
    {
      echo ' [ '.$i.' ] '; 
    }	
      else 
    {
      echo ' <a href="index.php?page='.$i.'">'.$i.'</a> ';
    }
    }
    echo '</p>';
    ?>
     
      </body>
    </html>
    Merci de votre aide !!

  2. #2
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 497
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 497
    Points : 12 597
    Points
    12 597
    Par défaut
    Bonjour,

    Est-tu sur que les requêtes sont bonne , car je viens de tester ton code hors requête et il fonctionne parfaitement.

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2011
    Messages
    31
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2011
    Messages : 31
    Points : 13
    Points
    13
    Par défaut re
    la requête ou je suis sur quelle fonctionne est celle ou je sélectionne les éléments des $_POST mais le reste devrait fonctionner mais je ne vois pas pourquoi ça ne fonctionne pas

    PS: je suis sous postgresql et pas mysql peut etre un lien avec l'erreur

  4. #4
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 497
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 497
    Points : 12 597
    Points
    12 597
    Par défaut
    ok essaye ceci pour voir

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
     
    <?php
    include('connexion.inc');
    ?>
    <html>
    <head>
        <title>Info-commune</title>
    </head>
    <body>
     
    <?php
    $messagesParPage=15;
    $retour_total=pg_query('SELECT COUNT(*) AS total FROM communes');
    $donnees_total=pg_fetch_assoc($retour_total);
    $total=$donnees_total['total'];
     
     
    $nombreDePages=ceil($total/$messagesParPage);
     
    if(isset($_GET['page']))
    {
        $pageActuelle=intval($_GET['page']);
     
        if($pageActuelle>$nombreDePages)
        {
            $pageActuelle=$nombreDePages;
        }
    }
    else
    {
        $pageActuelle=1;
    }
     
    $premiereEntree=($pageActuelle-1)*$messagesParPage;
     
    //
    //$req = $connexion->prepare("SELECT * FROM communes Where nom like  '$cherchnom%'or  dept='$cherchdep'  or region = '$cherchreg' LIMIT '.$premiereEntree.', '.$messagesParPage.' ");
    //$req->execute();
    //$req->setFetchMode(PDO::FETCH_ASSOC);
    //$Idd = 1;
    //while ($affichage = $req->fetchObject()) {
    //?>
    <!---->
    <!--<table>-->
    <!--    <thead>-->
    <!--    <tr>-->
    <!--        <td><font size="2" ><b>N&deg;</b></font></td>-->
    <!--        <td><font size="2" ><b>Nom</b></font></td>-->
    <!--        <td><font size="2" ><b>Population</b></font></td>-->
    <!--        <td><font size="2" ><b>Departement</b></font></td>-->
    <!--        <td><font size="2" ><b>N&deg; commune</b></font></td>-->
    <!--        <td><font size="2" ><b>R&eacute;gion</b></font></td>-->
    <!--    </tr>-->
    <!--    </thead>-->
    <!--    <tr>-->
    <!--        <td>--><?php //echo $Idd ?><!--</td>-->
            <td><?php echo '<a href="recherche.php?nom_ascii_maj='.$affichage->nom_ascii_maj.'&region='.$affichage->region.'&population='.$affichage->population.'&departement='.$affichage->dept ?>"><?php echo $affichage->nom_ascii_maj ?></a></td>
            <td><?php echo $affichage->population ?></td>
            <td><?php echo $affichage->dept ?></td>
            <td><?php echo $affichage->comm ?></td>
            <td><?php echo $affichage->region ?></td>
    <!--    </tr>-->
    <!--    --><?php
    //    $Idd = $Idd + 1;
    //    }
    //    ?>
    <!--</table>-->
     
    <?php
    echo '<p align="center">Page : ';
    for($i=1; $i<=$nombreDePages; $i++)
    {
        if($i==$pageActuelle)
        {
            echo ' [ '.$i.' ] ';
        }
        else
        {
            echo ' <a href="index.php?page='.$i.'">'.$i.'</a> ';
        }
    }
    echo '</p>';
    ?>
     
    </body>
    </html>

  5. #5
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2011
    Messages
    31
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2011
    Messages : 31
    Points : 13
    Points
    13
    Par défaut re
    j'ai toujours le meme problème y page blanche s'affiche avec 'Page : ' en haut au centre de la page

    et je viens de tester :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <?php
    $messagesParPage=15;
    $retour_total= pg_query("SELECT COUNT(*) AS total FROM communes");
    $donnees_total=pg_fetch_assoc($retour_total);
    $total=$donnees_total['total'];
     echo $messagesParPage;
     echo $retour_total;
     echo $donnees_total;
     echo $total;
    ?>
    juste ça mais rien ne s'affiche sauf 15 soit le nombre par page ...

  6. #6
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 497
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 497
    Points : 12 597
    Points
    12 597
    Par défaut
    Donc ta requête ne retourne rien,

    Essaye en PDO

    juste pour tester

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    $dbh = new PDO("pgsql:dbname=$dbname;host=$host", $username, $password ); 
     
    $sql = 'SELECT COUNT(*) AS total FROM communes'
    $stmt = $dbh->prepare($sql);
    $stmt->execute();
    $result = $stmt->fetch(PDO::FETCH_ASSOC)
     
    $total=$result['total'];
    echo $messagesParPage;
    echo $retour_total;
    echo $donnees_total;
    echo $total;

  7. #7
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2011
    Messages
    31
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2011
    Messages : 31
    Points : 13
    Points
    13
    Par défaut re
    Toujours rien , je suis au bord de la crise de nerf et j'ai aussi tester ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    <?php
    $messagesParPage=15;
    $retour_total= $connexion->prepare("SELECT COUNT(*) AS total FROM communes");
    $retour_total->execute();
    $donnees_total = $retour_total->fetchAll();
     
    //$donnees_total=pg_fetch_assoc($retour_total);
    $total=$donnees_total['total'];
     echo $messagesParPage;
     echo $retour_total;
     echo $donnees_total;
     echo $total;
    ?>
    sans succes

  8. #8
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 497
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 497
    Points : 12 597
    Points
    12 597
    Par défaut
    Que donne ceci dans PgAdmin III

    Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    SELECT COUNT(*) AS total FROM communes

  9. #9
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2011
    Messages
    31
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2011
    Messages : 31
    Points : 13
    Points
    13
    Par défaut re
    total
    36681

  10. #10
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 497
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 497
    Points : 12 597
    Points
    12 597
    Par défaut
    ok dans une page test.php, essaye ceci

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    $dbh = new PDO("pgsql:dbname=$dbname;host=$host", $username, $password ); 
     
    $sql = 'SELECT COUNT(*) AS total FROM communes'
    $stmt = $dbh->prepare($sql);
    $stmt->execute();
    $result = $stmt->fetch(PDO::FETCH_ASSOC)
     
    echo '<pre>';
     
    var_dump($result)
    echo '</pre>';
    dit moi ce que cela retourne et n'oublie pas de modifier les valeurs de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    $dbh = new PDO("pgsql:dbname=$dbname;host=$host", $username, $password );

  11. #11
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2011
    Messages
    31
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2011
    Messages : 31
    Points : 13
    Points
    13
    Par défaut re
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    <?php
    try
    {
    $connexion = new PDO("pgsql:host=localhost;dbname=projetweb",
                                "cl3d","bonjour");
    }catch(Exception $e){
        echo 'Echec de la connexion à la base de données';
        exit();
    }
    ?>
    <html>
    <head>
        <title>Info-commune</title>
    </head>
    <body>
     
    <?php
     
     
    $sql = 'SELECT COUNT(*) AS total FROM communes'
    $stmt = $connexion->prepare($sql);
    $stmt->execute();
    $result = $stmt->fetch(PDO::FETCH_ASSOC)
     
    echo '<pre>';
     
    var_dump($result)
    echo '</pre>';
    ?>
     
    </body>
    </html>
    j'ai mi ça aucun affichage je comprends rien la !!

  12. #12
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 497
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 497
    Points : 12 597
    Points
    12 597
    Par défaut
    Et celui-ci

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
     
    <?php
    try
    {
    $connexion = new PDO("pgsql:host=localhost;dbname=projetweb",
                                "cl3d","bonjour");
    }catch(Exception $e){
        echo 'Echec de la connexion à la base de données';
        exit();
    }
    ?>
    <html>
    <head>
        <title>Info-commune</title>
    </head>
    <body>
     
    <?php
     
     
    $sql = 'SELECT COUNT(*) AS total FROM communes'
    $stmt = $connexion->prepare($sql);
    $stmt->execute();
    $result = $stmt->fetchAll(PDO::FETCH_ASSOC)
     
    echo '<pre>';
     
    var_dump($result)
    echo '</pre>';
    ?>
     
    </body>
    </html>

  13. #13
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2011
    Messages
    31
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2011
    Messages : 31
    Points : 13
    Points
    13
    Par défaut re
    page blanche u_u ça me gave merci vraiment ue tu m'aides car seul jvais claquer l'ordi

  14. #14
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 497
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 497
    Points : 12 597
    Points
    12 597
    Par défaut
    Ok j'ai vu

    voila

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
     
     
    <?php
    try
    {
    $connexion = new PDO("pgsql:host=localhost;dbname=projetweb",
                                "cl3d","bonjour");
    }catch(Exception $e){
        echo 'Echec de la connexion à la base de données';
        exit();
    }
    ?>
    <html>
    <head>
        <title>Info-commune</title>
    </head>
    <body>
     
    <?php
     
     
    $sql = 'SELECT COUNT(*) AS total FROM communes';
    $stmt = $connexion->prepare($sql);
    $stmt->execute();
    $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
     
    echo '<pre>';
     
    var_dump($result);
    echo '</pre>';
    ?>
     
    </body>
    </html>

  15. #15
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2011
    Messages
    31
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2011
    Messages : 31
    Points : 13
    Points
    13
    Par défaut re ça va venir =)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    array(1) {
      [0]=>
      array(1) {
        ["total"]=>
        int(36681)
      }
    }

  16. #16
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 497
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 497
    Points : 12 597
    Points
    12 597
    Par défaut
    Ok adapte à ta page et récupère comme ci

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    $total=$result[0]['total'];

  17. #17
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2011
    Messages
    31
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2011
    Messages : 31
    Points : 13
    Points
    13
    Par défaut re
    Je fais les modification et jte dis quoi merci beaucoup

  18. #18
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2011
    Messages
    31
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2011
    Messages : 31
    Points : 13
    Points
    13
    Par défaut re
    Bon la pagination fonctionne mais le tableau de resultat lui ne s'affiche pas maintenant ><
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    <?php
    include('connexion.inc');
    ?>
    <html>
        <head>
          <title>Info-commune</title>
        </head>
      <body>
      <form method="post" action="index.php">
     <fieldset> <legend>Choississez vos critères </legend>
        <label>Commune</label> <input type="text" id="nom" name="nom" style="width:150px;" />
       <label>Departement</label> <input type="text" id="dept" name="dept" style="width:150px;" />
    <label>Population</label> <input type="text" id="pop" name="pop" style="width:150px;" />
    <label>Region</label> <input type="text" id="reg" name="reg" style="width:150px;" />
    <input type='submit' value='Valider'>
    </fieldset>
    </form>
    <?php
       if (isset($_POST['nom'])) {
                                            $cherchnom = $_POST['nom'];
                                        } else {
                                            $cherchnom = '';
                                                                               }
                                        if (isset($_POST['population'])) {
                                            $cherchpop = $_POST['population'];
                                        } else {
                                            $cherchpop = '';
                                        }
                                        if (isset($_POST['departement'])) {
                                            $cherchdep = $_POST['departement'];
                                        } else {
                                            $cherchdep = '';
                                        }
                                         if (isset($_POST['region'])) {
                                            $cherchreg = $_POST['region'];
                                        } else {
                                            $cherchreg = '';
                                        }
     
      $messagesParPage=15; 
      $retour_total = "SELECT COUNT(*) AS total FROM communes Where nom like  '$cherchnom%'or  dept='$cherchdep'  or region = '$cherchreg'";
    $donnees_total = $connexion->prepare($retour_total);
    $donnees_total->execute();
    $result = $donnees_total->fetchAll(PDO::FETCH_ASSOC);
     
    $total=$result[0]['total'];
     
      $nombreDePages=ceil($total/$messagesParPage);
     
      if(isset($_GET['page'])) 
    {
         $pageActuelle=intval($_GET['page']);
     
      if($pageActuelle>$nombreDePages) 
    {
         $pageActuelle=$nombreDePages;
    }
    }
       else 
    {
        $pageActuelle=1;  
    }
     
      $premiereEntree=($pageActuelle-1)*$messagesParPage; 
     
     
     
      $req = $connexion->prepare("SELECT * FROM communes Where nom like  '$cherchnom%'or  dept='$cherchdep'  or region = '$cherchreg' LIMIT '.$premiereEntree.', '.$messagesParPage.' ");
      $req->execute();
      $req->setFetchMode(PDO::FETCH_ASSOC);
      $Idd = 1;
        while ($affichage = $req->fetchObject()) {                                     
    ?>
     
    <table>
      <thead>
        <tr>
          <td><font size="2" ><b>N&deg;</b></font></td>
          <td><font size="2" ><b>Nom</b></font></td>
          <td><font size="2" ><b>Population</b></font></td>
          <td><font size="2" ><b>Departement</b></font></td>
          <td><font size="2" ><b>N&deg; commune</b></font></td>
          <td><font size="2" ><b>R&eacute;gion</b></font></td>
         </tr>
        </thead>
          <tr>
    	<td><?php echo $Idd ?></td>
            <td><?php echo '<a href="recherche.php?nom_ascii_maj='.$affichage->nom_ascii_maj.'&region='.$affichage->region.'&population='.$affichage->population.'&departement='.$affichage->dept ?>"><?php echo $affichage->nom_ascii_maj ?></a></td>
            <td><?php echo $affichage->population ?></td>
            <td><?php echo $affichage->dept ?></td>
            <td><?php echo $affichage->comm ?></td>
            <td><?php echo $affichage->region ?></td>
           </tr>
    <?php
      $Idd = $Idd + 1;
    }
    ?>
    </table>
     
    <?php
      echo '<p align="center">Page : '; 
      for($i=1; $i<=$nombreDePages; $i++)
    {
      if($i==$pageActuelle) 
    {
      echo ' [ '.$i.' ] '; 
    }	
      else 
    {
      echo ' <a href="index.php?page='.$i.'">'.$i.'</a> ';
    }
    }
    echo '</p>';
    ?>
     
      </body>
    </html>

  19. #19
    Membre confirmé Avatar de humitake
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2010
    Messages
    399
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2010
    Messages : 399
    Points : 578
    Points
    578
    Par défaut
    Bonjour,

    Ce n'est pas comme ça que l'on fait une requête préparé, la ce que tu lui donne ça sert a rien de passer par la méthode prepare autant utiliser la méthode query().
    L'intérêt de la méthode prepare() est d'échaper les caractères 'interdits', pour cela il faut que tu revoie la syntaxe : doc prepare().

    Est-ce que ton total n'est pas vide ?
    Rajoute var_dump($total); juste après $total=$result[0]['total'];Sinon est-ce que tu as un message d'erreur ?

    Est-ce que tu as bien quelques chose qui est renvoyé ?

    Ajoute la ligne suivante dans ton while() : var_dump($affiche);.

    Affiche ta requête sql généré avant son exécution :
    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    var_dump("SELECT * FROM communes Where nom like  '$cherchnom%'or  dept='$cherchdep'  or region = '$cherchreg' LIMIT '.$premiereEntree.', '.$messagesParPage.' ");
    $req = $connexion->prepare("SELECT * FROM communes Where nom like  '$cherchnom%'or  dept='$cherchdep'  or region = '$cherchreg' LIMIT '.$premiereEntree.', '.$messagesParPage.' ");
    $req->execute();

  20. #20
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2011
    Messages
    31
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2011
    Messages : 31
    Points : 13
    Points
    13
    Par défaut re
    Les requêtes fonctionnent c'est juste l'affichage maintenant
    voici mon nouveau code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    <?php
    include('connexion.inc');
    ?>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
    <head>
     <meta charset="UTF-8" />
     <title>Info-Communes</title>
     <link rel="stylesheet" href="style.css" type="text/css"/>
    </head>
    <body>
     <center> <h1>Projet </h1></center>
     
      <form method="post" action="index.php">
     <div id="critere">
     <fieldset> <legend>Choississez vos critères </legend>
        <label>Commune</label> <input type="text" id="nom" name="nom" style="width:150px;" />
       <label>Departement</label> <input type="text" id="dept" name="dept" style="width:150px;" />
    <label>Population</label> <input type="text" id="pop" name="pop" style="width:150px;" />
    <label>Region</label> <input type="text" id="reg" name="reg" style="width:150px;" />
    <input type='submit' value='Valider'>
    </fieldset>
    </form>
      <div style="overflow:auto; width:850px; height:300px">
                                    <table>
                                        <thead>
                                            <tr>
                                                <td><font size="2" ><b>N&deg;</b></font></td>
                                                <td><font size="2" ><b>Nom</b></font></td>
                                                <td><font size="2" ><b>Population</b></font></td>
                                                <td><font size="2" ><b>Departement</b></font></td>
                                                <td><font size="2" ><b>N&deg; commune</b></font></td>
                                                <td><font size="2" ><b>R&eacute;gion</b></font></td>
     
                                            </tr>
                                        </thead>
     
                                        <?php
     
    $messagesParPage=15; 
      $retour_total = "SELECT COUNT(*) AS total FROM communes Where nom like  '$cherchnom%'or  dept='$cherchdep'  or region = '$cherchreg' ";
    $donnees_total = $connexion->prepare($retour_total);
    $donnees_total->execute();
    $result = $donnees_total->fetchAll(PDO::FETCH_ASSOC);
     
    $total=$result[0]['total'];
     
      $nombreDePages=ceil($total/$messagesParPage);
     
      if(isset($_GET['page'])) 
    {
         $pageActuelle=intval($_GET['page']);
     
      if($pageActuelle>$nombreDePages) 
    {
         $pageActuelle=$nombreDePages;
    }
    }
       else 
    {
        $pageActuelle=1;  
    }
     
      $premiereEntree=($pageActuelle-1)*$messagesParPage; 
     
                                        if (isset($_POST['nom'])) {
                                            $cherchnom = $_POST['nom'];
                                        } else {
                                            $cherchnom = '';
                                                                               }
                                        if (isset($_POST['pop'])) {
                                            $cherchpop = $_POST['pop'];
                                        } else {
                                            $cherchpop = '';
                                        }
                                        if (isset($_POST['departement'])) {
                                            $cherchdep = $_POST['departement'];
                                        } else {
                                            $cherchdep = '';
                                        }
                                         if (isset($_POST['region'])) {
                                            $cherchreg = $_POST['region'];
                                        } else {
                                            $cherchreg = '';
                                        }
     
    $req = $connexion->prepare("SELECT * FROM communes Where nom like  '$cherchnom%'or  dept='$cherchdep'  or region = '$cherchreg' ");
    $req->execute();
    $req->setFetchMode(PDO::FETCH_ASSOC);
     
                                        $Idd = 1;
                                        while ($affichage = $req->fetchObject()) {
                                            ?>
                                            <tr>
                                                <td><?php echo $Idd ?></td>
                                                <td><?php echo '<a href="recherche.php?nom_ascii_maj='.$affichage->nom_ascii_maj.'&region='.$affichage->region.'&population='.$affichage->population.'&departement='.$affichage->dept ?>"><?php echo $affichage->nom_ascii_maj ?></a></td>
                                                <td><?php echo $affichage->population ?></td>
                                                <td><?php echo $affichage->dept ?></td>
                                                <td><?php echo $affichage->comm ?></td>
                                                <td><?php echo $affichage->region ?></td>
     
                                            </tr>
                                            <?php
                                            $Idd = $Idd + 1;
                                        }
                                        ?>
     
     
                                    </table>
                                    </div>
                                     <?php echo '<p align="center">Page : '; 
      for($i=1; $i<=$nombreDePages; $i++)
    {
      if($i==$pageActuelle) 
    {
      echo ' [ '.$i.' ] '; 
    }	
      else 
    {
      echo ' <a href="index.php?page='.$i.'">'.$i.'</a> ';
    }
    }
    echo '</p>'; ?>
     
    </body>
    </html>
    et voila un exemple d'affichage :
    http://www.hostingpics.net/viewer.ph...8171projet.png


    il me reste : LIMIT '$premiereEntree','$messagesParPage' a placer dans la requête mais si je mets cela les resultats de la table disparaissent et la pagination ne le prends pas en compte non plus et je voudrais associer la pagination aux résultats de la table

Discussions similaires

  1. pagination en php
    Par rochdi123 dans le forum Langage
    Réponses: 1
    Dernier message: 24/08/2009, 10h07
  2. pagination en php
    Par hadjiphp dans le forum Langage
    Réponses: 9
    Dernier message: 12/06/2009, 10h25
  3. pagination en php
    Par biloute73 dans le forum PHP & Base de données
    Réponses: 5
    Dernier message: 23/03/2009, 13h41
  4. Recherche en pagination en PHP
    Par ismonetooo dans le forum PHP & Base de données
    Réponses: 4
    Dernier message: 10/10/2008, 16h04
  5. Pagination avec PHP et Mysql
    Par __fabrice dans le forum Flash
    Réponses: 2
    Dernier message: 27/09/2006, 14h17

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo