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 avec class pdo / mysql


Sujet :

PHP & Base de données

  1. #1
    Membre éprouvé
    Inscrit en
    Janvier 2008
    Messages
    1 159
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 1 159
    Par défaut Pagination avec class pdo / mysql
    Bonjour,

    j'ai afficher la liste de ma table avec ma class sur mon theme actuel j'ai une fausse pagination.

    Je souhaiterai remplacer par une pagination pdo avec une classe.

    j'ai trouvé ceci :

    voici ce que j'ai fait j'ai bien une pagination 1 à 3.

    Mais l'annuaire reste complet sur chaque page plutot que de se diviser en 3 pages.

    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
    		<div class="row span-none">
     
    								foreach($managerServicePublic->getListGroupByPivot() as $lstAll) 
    								{
    									<div class="col-md-4">
    										<a href="listing-details.html">
    											<div class="list-mig-like-com com-mar-bot-30">
     
    												<div class="list-mig-lc-con">
     
    													<h5>echo'$lstAll->getPivot()'</h5>
    													<h6>echo'$lstAll->getTypeService()'</h6>
    													<p>echo'$lstAll->getCommune()'</p>
    												</div>
    											</div>
    										</a>
    									</div>
     
    										}
     
     
    $nbElements = $managerServicePublic->countGroupByPivot();
    $PaginationFinal = new Pagination();
    $PaginationFinal->setCurrentPage($_GET['page']);
    $PaginationFinal->setInnerLinks(3);
    $PaginationFinal->setNbElementsInPage(12);
    $PaginationFinal->setNbMaxElements($nbElements);
    $paginationFinal = $PaginationFinal->renderBootstrapPagination();
     
    echo'$paginationFinal';
    mes fonctions des mes classes :
    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
     
     
    public function countGroupByPivot()
    	{
    		return $this->db->query('SELECT COUNT(*) FROM service group by pivot')->fetchColumn();
    	}
     
    public function getListGroupByPivotLocal($debut = -1, $limite = -1)
    	{
     
    		$listeService = array();
     
    		$sql = 'SELECT id_service,id_data,code_insee,date_maj,pivot,..... FROM service group by pivot';
     
     
    		if ($debut != -1 || $limite != -1)
    		$sql .= ' LIMIT ' . (int) $debut . ', ' . (int) $limite;
     
    		$requete = $this->db->query($sql);
     
    		while ($Service = $requete->fetch(PDO::FETCH_ASSOC))
    		$listeService[] = new Service ($Service);
     
    		$requete->closeCursor();
     
     
    		return $listeService;
     
     
    	}

    j'ai du effectuer un group by car dans ma base de donnée j'ai des infos d'annaire avec des pivot identique tels que mairie,etc,..
    merci pour votre aide.

  2. #2
    Membre Expert

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 583
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 583
    Par défaut
    Salut,

    Ton code returne t-il des erreurs? pourquoi
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    echo'$lstAll->getPivot()'
    n'a t'il pas de balise php? ta classe pagination? Ton code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    $nbElements = $managerServicePublic->countGroupByPivot();
    $PaginationFinal = new Pagination();
    $PaginationFinal->setCurrentPage($_GET['page']);
    $PaginationFinal->setInnerLinks(3);
    $PaginationFinal->setNbElementsInPage(12);
    $PaginationFinal->setNbMaxElements($nbElements);
    $paginationFinal = $PaginationFinal->renderBootstrapPagination();
    devrait peut-être avant l'affichage, de plus
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    foreach($managerServicePublic->getListGroupByPivot() as $lstAll)
    ou est initialisé .

  3. #3
    Membre éprouvé
    Inscrit en
    Janvier 2008
    Messages
    1 159
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 1 159
    Par défaut
    Salut,


    n'a t'il pas de balise php? ta classe pagination?

    -> ici c'est l'initialisation de la classe sur ma page annuaire.

    -> j'ai bien un <?php j'ai juste affiché la partie concerné de la page.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    $nbElements = $managerServicePublic->countGroupByPivot();
    $PaginationFinal = new Pagination();
    $PaginationFinal->setCurrentPage($_GET['page']);
    $PaginationFinal->setInnerLinks(3);
    $PaginationFinal->setNbElementsInPage(12);
    $PaginationFinal->setNbMaxElements($nbElements);
    $paginationFinal = $PaginationFinal->renderBootstrapPagination();
    devrait peut-être avant l'affichage, de plus
    foreach($managerServicePublic->getListGroupByPivot() as $lstAll) ou est initialisé
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $managerServicePublic.

    -> au debut de ma page j'ai initialiser :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $managerServicePublic = new ServicePublicManager_PDO($db);
    include '../lib/pagination.class.php';
    mon code fonctionne très bien pour l'affichage de l'annuaire sauf la pagination que je veux .

    par contre j'ai fais un print_r de SELECT COUNT(*) FROM ef_service group by pivot et ca renvoi
    43 et le resultat su phpmyadmin :
    43
    151
    198
    53
    211
    367
    83
    39
    3
    245
    250
    82
    353
    9
    1640
    3
    27
    284
    181
    282
    43
    94
    161
    183
    201
    165
    159
    1753
    589
    122
    Je ne comprend pas pourquoi il affiche pas un total mais plusieurs et que la fonction la 1 valeur du count ?

    merci

  4. #4
    Membre Expert

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 583
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 583
    Par défaut
    par contre j'ai fais un print_r de SELECT COUNT(*) FROM ef_service group by pivot et ca renvoi
    43 et le resultat su phpmyadmin
    C'est normal https://secure.php.net/manual/fr/pdo...etchcolumn.php fetchcolumn retourne 1 résultat, or le group by https://www.w3schools.com/sql/trysql...select_groupby va grouper tes éléments par pivot et puisque tu as plusieurs pivots différents.

    Dans
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    foreach($managerServicePublic->getListGroupByPivot() as $lstAll)
    Tu ne modifie pas les paramètres, donc puisque tes valeurs sont
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $debut = -1, $limite = -1
    ton limite n'est pas appliqué. Fait un var_dump de ta requête sql pour en être certains.

    Tu dois récupérer ta page puis passer en paramètre de ta fonction, le nombre d'élément ce qui te donnera le début $debut=numpage*nombreelement et ta limite ici 12.

  5. #5
    Membre éprouvé
    Inscrit en
    Janvier 2008
    Messages
    1 159
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 1 159
    Par défaut
    j'ai fait un var dump

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    foreach($managerService->getListGroupByPivot() as $lstAll) 
    {
    	var_dump($lstAll);
    mais rien est retournée ?

    merci pour votre aide.

  6. #6
    Membre Expert

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 583
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 583
    Par défaut
    Le var_dump sert juste à débugger, si tu fais un die après le var_dump?
    Dans ton foreach
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    // si on a une page et que c'est un entier alors ok si on initialise à null
    $page = (!empty($_GET['page']) && is_int($_GET['page'])) ? $_GET['page'] : null;
    $limit = 12;
    // le debut corresond au nombre d'élément par page * le numéro de la page - 1, exemple page 2 j'ai donc 2- 1 * 12 = 12. Vaut mieux utiliser une variable pour le nombre élément.
    $debut = ($page - 1) * $limit;
    foreach($managerServicePublic->getListGroupByPivot($debut, $limit) as $lstAll)
    J'ai pas tester il faut que tu adaptes je pense

  7. #7
    Modératrice
    Avatar de Celira
    Femme Profil pro
    Développeuse PHP/Java
    Inscrit en
    Avril 2007
    Messages
    8 633
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeuse PHP/Java
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 8 633
    Par défaut
    Il vaudrait mieux initialiser le numéro de page à 1 par défaut, parce que null-1 ça fait un truc bizarre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    // si on a une page et que c'est un entier alors ok si on initialise à 1
    $page = (!empty($_GET['page']) && is_int($_GET['page'])) ? $_GET['page'] : 1;
    Modératrice PHP
    Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)
    Cherchez un peu avant poser votre question : Cours et Tutoriels PHP - FAQ PHP - PDO une soupe et au lit !.

    Affichez votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur) et [C=php][/C]

  8. #8
    Membre éprouvé
    Inscrit en
    Janvier 2008
    Messages
    1 159
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 1 159
    Par défaut
    merci j'ai corrigé alors j'ai abandonné le group by mais conservant la class par contre en allant a la page 2 je me rend compte qu'il ne garde pas les post du formulaire de recherche.
    Je voudrait donc les passer dans le GET en meme temps que le numero de la page.

    Mais je ne sais pas comment ?

    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
    $nbElements = $managerServicePublic->countDistinctNomServicePublic();
    $PaginationFinal = new Pagination();
    $PaginationFinal->setCurrentPage($_GET['page']);
    $PaginationFinal->setInnerLinks(12);
    $PaginationFinal->setNbElementsInPage(12);
    $PaginationFinal->setNbMaxElements($nbElements);
    $paginationFinal = $PaginationFinal->renderBootstrapPagination();
    /* On calcule le numéro du premier élément à récupérer */
    $page = (!empty($_GET['page']) ? $_GET['page'] : 1);
     
    $debut = ($page - 1) * 12;		
     
    /*affichage apres recherche formulaire*/
     
    							if(isset($_POST['search-category']))
    							{
     
     
    							$lstAll=$managerServicePublic->getListBySearch($debut,12,$mots_f,$ville_f);
     
     
    							if(!empty($lstAll))
    							{
    								/*si tableau pas vide*/
    							foreach($managerServicePublic->getListBySearch($debut,12,$mots_f,$ville_f) as $lstAll) 
    								{
     
    									$body.='
     
    									<div class="col-md-3">
    										<a href="services-publics-annuaire-details.php?sub='.$lstAll->getPivotLocal().'&id='.$lstAll->getIdServicePublic().'">
    											<div class="list-mig-like-com com-mar-bot-30">
     
    												<div class="list-mig-lc-con">
     
    													<p style="color:white;font-size:1.0em;">'.$lstAll->getNomServicePublic().'</p>
    													<p style="color:white;font-size:1.0em;">'.$lstAll->getCodePostal().'</p>
    												</div>
    											</div>
    										</a>
    									</div>
    									';
     
     
    								}
     
    										$body.='
    										<br /><br />
    										<div class="center">
     
     
    										'.$paginationFinal.'
     
    										</div>
     
    									<br />';
     
    							}
    merci pour votre aide.

  9. #9
    Membre Expert

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 583
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 583
    Par défaut
    Merci @Celira pour la correction

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    je me rend compte qu'il ne garde pas les post du formulaire de recherche.
    Exact puisque ton lien <a> est une requète http de type GET, tu dois donc le passer en paramètre puisque ton autre paramètre de recherche est perdu lors du clique sur le lien.
    Je pense ici que tu vas devoir modifier ta classe de pagination, pour que paginationFinal retourne dans le lien tes paramètres de recherche.
    Sans plus d'information je ne peux pas t'aider plus.

  10. #10
    Membre éprouvé
    Inscrit en
    Janvier 2008
    Messages
    1 159
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 1 159
    Par défaut
    Bonjour,

    je n'ai pas encore trouvé la solution je dois donc modifier la classe pagination mais je ne sais pas quels modifications effectuées ?

    La classe pagination :

    Code php : 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
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    <?php
     
    /**
     * Generate a Pagination (with Bootstrap).
     *
     * @version 1.0.0
     * @link https://github.com/Zheness/Pagination/ Github Repo
     * @author Zheness
     */
    class Pagination {
     
        private $nbMaxElements = 200;
        private $nbElementsInPage = 20;
        private $currentPage = 1;
        private $url = '?page={i}';
        private $innerLinks = 2;
        private $linksSeparator = '...';
     
        /**
         * Set the maximum elements in your database. (Or other way)
         * 
         * Example :
         * 
         * I have 200 articles in my database, so I type :
         * 
         * $Pagination->setNbMaxElements(200);
         *
         * @param int $int The maximum elements
         * @author Zheness
         */
        public function setNbMaxElements($int) {
            $this->nbMaxElements = (int) $int;
        }
     
        /**
         * Set the number of elements to display in the page.
         * 
         * Example :
         * 
         * I would display 20 articles per pages, so I type :
         * 
         * $Pagination->setNbElementsInPage(20);
         *
         * @param int $int The number of elements
         * @author Zheness
         */
        public function setNbElementsInPage($int) {
            $this->nbElementsInPage = (int) $int;
        }
     
        /**
         * Set the current page
         * 
         * Example :
         * 
         * The current page is the 5, so I type :
         * 
         * $Pagination->setCurrentPage(5);
         *
         * @param int $int The current page
         * @author Zheness
         */
        public function setCurrentPage($int) {
            $this->currentPage = (int) $int;
        }
     
        /**
         * Set the url in the links. You MUST include "{i}" where you want display the number of the page.
         * 
         * Example :
         * 
         * I would display my articles on "articles.php?page=X" where X is the number of page. So I type :
         * 
         * $Pagination->setUrl("articles.php?page={i}");
         * 
         * Why {i} ? Because the number of page can be placed everywhere. If you have your url like this "articles/month/08/page/X/sort/date-desc", you can place {i} instead of X.
         *
         * @param string $string The url in the link
         * @author Zheness
         */
        public function setUrl($string) {
            $this->url = $string;
        }
     
        /**
         * Set the number of links before and after the current page
         * 
         * Example :
         * 
         * The current page is the 5, and I want 3 links after and before, so I type :
         * 
         * $Pagination->setInnerLinks(3);
         *
         * @param int $int The number of links before and after the current links
         * @author Zheness
         */
        public function setInnerLinks($int) {
            $this->innerLinks = (int) $int;
        }
     
        /**
         * Set the separtor between links.
         * 
         * Example :
         * 
         * I would display " - " between my links, so I type :
         * 
         * $Pagination->setLinksSeparator(" - ");
         * 
         * By default "..." is display.
         *
         * @param string $string The url in the link
         * @author Zheness
         */
        public function setLinksSeparator($string) {
            $this->linksSeparator = $string;
        }
     
        /**
         * This is the function to call for render the Pagination.
         * 
         * You have just to configure the options and call this function.
         *
         * @return string The HTML Pagination (it use Bootstrap)
         * @author Zheness
         */
        public function renderBootstrapPagination() {
            $array_pagination = $this->generateArrayPagination();
            $html = $this->generateHtmlPagination($array_pagination);
            return $html;
        }
     
        /**
         * Generate the Pagination in array.
         *
         * @return array Each value is the link to display.
         * @author Zheness
         */
        private function generateArrayPagination() {
            $array_pagination = array();
            $keyArray = 0;
     
            $subLinks = $this->currentPage - $this->innerLinks;
            $nbLastLink = ceil($this->nbMaxElements / $this->nbElementsInPage);
     
            if ($this->currentPage > 1) {
                $array_pagination[$keyArray++] = '<a href="' . str_replace('{i}', 1, $this->url) . '">1</a>';
            }
            if ($subLinks > 2) {
                $array_pagination[$keyArray++] = $this->linksSeparator;
            }
            for ($i = $subLinks; $i < $this->currentPage; $i++) {
                if ($i >= 2) {
                    $array_pagination[$keyArray++] = '<a href="' . str_replace('{i}', $i, $this->url) . '">' . $i . '</a>';
                }
            }
     
            $array_pagination[$keyArray++] = '<b>' . $this->currentPage . '</b>';
     
            for ($i = ($this->currentPage + 1); $i <= ($this->currentPage + $this->innerLinks); $i++) {
                if ($i < $nbLastLink) {
                    $array_pagination[$keyArray++] = '<a href="' . str_replace('{i}', $i, $this->url) . '">' . $i . '</a>';
                }
            }
            if (($this->currentPage + $this->innerLinks) < ($nbLastLink - 1)) {
                $array_pagination[$keyArray++] = $this->linksSeparator;
            }
            if ($this->currentPage != $nbLastLink) {
                $array_pagination[$keyArray++] = '<a href="' . str_replace('{i}', $nbLastLink, $this->url) . '">' . $nbLastLink . '</a>';
            }
     
            return $array_pagination;
        }
     
        /**
         * Generate the HTML pagination with the array in parameter
         *
         * @param array $array_pagination The array generate with previous function.
         * @return string Pagination in HTML. Use Bootstrap
         * @author Zheness
         */
        private function generateHtmlPagination($array_pagination) {
            $html = "";
            $html .= '<div class="pagination">';
            $html .= '<ul>';
            if ($this->nbMaxElements) {
                foreach ($array_pagination as $v) {
                    if ($v == $this->linksSeparator) {
                        $html .= '<li class="disabled"><span>' . $this->linksSeparator . '</span></li>';
                    } else if (preg_match("/<b>(.*)<\/b>/i", $v)) {
                        $html .= '<li class="active"><span>' . strip_tags($v) . '</span></li>';
                    } else {
                        $html .= '<li>' . $v . '</li>';
                    }
                }
            } else {
                $html .= '<li class="active"><span>1</span></li>';
            }
            $html .= '</ul>';
            $html .= '</div>';
            return $html;
        }
     
    }

  11. #11
    Membre Expert

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 583
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 583
    Par défaut
    Peux tu me montrer le html généré pour deux trois liens dans ta pagination?

  12. #12
    Membre éprouvé
    Inscrit en
    Janvier 2008
    Messages
    1 159
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 1 159
    Par défaut
    merci voici le html généré :

    Code HTML : 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
    <div class="col-md-3">
    	<a href="?sub=MAIRIE&id=46381">
    		<div class="list-mig-like-com com-mar-bot-30">
     
    			<div class="list-mig-lc-con">
     
    				<p style="color:white;font-size:1.0em;">MAIRIE</p>
    				<p style="color:white;font-size:1.0em;">31230</p>
    			</div>
    		</div>
    	</a>
    </div>
     
     
    <div class="col-md-3">
    	<a href="?sub=MAIRIE&id=46383">
    		<div class="list-mig-like-com com-mar-bot-30">
     
    			<div class="list-mig-lc-con">
     
    				<p style="color:white;font-size:1.0em;">MAIRIE</p>
    				<p style="color:white;font-size:1.0em;">31550</p>
    			</div>
    		</div>
    	</a>
    </div>
     
     
    <div class="col-md-3">
    	<a href="?sub=MAIRIE&id=46385">
    		<div class="list-mig-like-com com-mar-bot-30">
     
    			<div class="list-mig-lc-con">
     
    				<p style="color:white;font-size:1.0em;">MAIRIE</p>
    				<p style="color:white;font-size:1.0em;">31280</p>
    			</div>
    		</div>
    	</a>
    </div>

    la pagination généré :

    Code HTML : Sélectionner tout - Visualiser dans une fenêtre à part
    <div class="pagination"><ul><li class="active"><span>0</span></li><li><a href="?page=1">1</a></li><li><a href="?page=2">2</a></li><li><a href="?page=3">3</a></li><li><a href="?page=4">4</a></li><li><a href="?page=5">5</a></li><li><a href="?page=6">6</a></li><li><a href="?page=7">7</a></li><li><a href="?page=8">8</a></li><li><a href="?page=9">9</a></li><li><a href="?page=10">10</a></li><li><a href="?page=11">11</a></li><li><a href="?page=12">12</a></li><li class="disabled"><span>...</span></li><li><a href="?page=464">464</a></li></ul></div>


    voici le code html de la page :

    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
    $mots_f=$_POST['search-category'];
    $ville_f=$_POST['search-city'];
    /**voici les deux variables du formulaire de recherche*/
     
     
    $nbElements = $managerServicePublic->countDistinctNomServicePublic();
    $PaginationFinal = new Pagination();
    $PaginationFinal->setCurrentPage($_GET['page']);
    $PaginationFinal->setInnerLinks(12);
    $PaginationFinal->setNbElementsInPage(12);
    $PaginationFinal->setNbMaxElements($nbElements);
    $paginationFinal = $PaginationFinal->renderBootstrapPagination();
    /* On calcule le numéro du premier élément à récupérer */
    // si on a une page et que c'est un entier alors ok si on initialise à 1
    $page = (!empty($_GET['page']) && is_int($_GET['page'])) ? $_GET['page'] : 1;
     
     
    $debut = ($page - 1) * 12;		
     
    /*affichage apres recherche formulaire*/
     
    if(isset($_POST['search-category']))
    {
     
     
    $lstAll=$managerServicePublic->getListBySearch($debut,12,$mots_f,$ville_f);
     
     
    if(!empty($lstAll))
    {
    	/*si tableau pas vide*/
    foreach($managerServicePublic->getListBySearch($debut,12,$mots_f,$ville_f) as $lstAll) 
    	{
     
    		$body.='
     
    		<div class="col-md-3">
    			<a href="?sub='.$lstAll->getPivotLocal().'&id='.$lstAll->getIdServicePublic().'">
    				<div class="list-mig-like-com com-mar-bot-30">
     
    					<div class="list-mig-lc-con">
     
    						<p style="color:white;font-size:1.0em;">'.$lstAll->getNomServicePublic().'</p>
    						<p style="color:white;font-size:1.0em;">'.$lstAll->getCodePostal().'</p>
    					</div>
    				</div>
    			</a>
    		</div>
    		';
     
     
    	}
     
    			$body.='
    			<br /><br />
    			<div class="center">
     
     
    			'.$paginationFinal.'
     
    			</div>
     
    		<br />';
    }

  13. #13
    Membre Expert

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 583
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 583
    Par défaut
    Tu dois modifier la méthode
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    generateArrayPagination
    de ta classe. Tu utilises composer? sinon tu peux étendre ta classe avec une class PaginationAddParam et tu ajoute une méthode addParam ou tu ajoutes les paramètres avec une expression régulière pour chaque url. Le plus rapide est de modifier la méthode si tu ne compte pas réuploader la classe à l'avenir.

    Dans ton code,
    (Nomme tes variables en camel case (motF, villeF).
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    // si on a déjà initialiser nos variables (premières page) alors pas besoin 
    if(empty($mots_f) || empty($ville_f))
    {
        // si on est ici c'est que forécement nos paramètres sont dans l'u
        $mots_f = (!empty($_GET['mot']) ? $_GET['mot'] : '');
        $ville_f = (!empty($_GET['ville']) ? $_GET['ville'] : '');
    }
    $paginationFinal = $PaginationFinal->renderBootstrapPagination($mots_f,$ville_f);
    Dans ta classe
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     public function renderBootstrapPagination(string $mots_f, string $ville_f) {
            $array_pagination = $this->generateArrayPagination($mots_f,$ville_f);
            $html = $this->generateHtmlPagination($array_pagination);
            return $html;
        }
    Puis ta fonction

    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
     private function generateArrayPagination(string $mots_f = "", string $ville_f = "") {
            $array_pagination = array();
            $keyArray = 0;
     
            $subLinks = $this->currentPage - $this->innerLinks;
            $nbLastLink = ceil($this->nbMaxElements / $this->nbElementsInPage);
     
            if ($this->currentPage > 1) {
                // on ajoute nos paramètres à l'url
                $array_pagination[$keyArray++] = '<a href="' . str_replace('{i}', 1, $this->url) . '&ville=' .$ville_f. '&mot=' . $mots_f. '">1</a>';
            }
            if ($subLinks > 2) {
                $array_pagination[$keyArray++] = $this->linksSeparator;
            }
            for ($i = $subLinks; $i < $this->currentPage; $i++) {
                if ($i >= 2) {
                    $array_pagination[$keyArray++] = '<a href="' . str_replace('{i}', $i, $this->url) . '">' . $i . '</a>';
                }
            }
     
            $array_pagination[$keyArray++] = '<b>' . $this->currentPage . '</b>';
     
            for ($i = ($this->currentPage + 1); $i <= ($this->currentPage + $this->innerLinks); $i++) {
                if ($i < $nbLastLink) {
                    $array_pagination[$keyArray++] = '<a href="' . str_replace('{i}', $i, $this->url) . '">' . $i . '</a>';
                }
            }
            if (($this->currentPage + $this->innerLinks) < ($nbLastLink - 1)) {
                $array_pagination[$keyArray++] = $this->linksSeparator;
            }
            if ($this->currentPage != $nbLastLink) {
                $array_pagination[$keyArray++] = '<a href="' . str_replace('{i}', $nbLastLink, $this->url) . '">' . $nbLastLink . '</a>';
            }
     
            return $array_pagination;
        }
    J'ai pas tester!
    Tu vas surement avoir des erreur logiquement à toi d'adapter, le reste tu peux le faire tout seul.

  14. #14
    Membre éprouvé
    Inscrit en
    Janvier 2008
    Messages
    1 159
    Détails du profil
    Informations forums :
    Inscription : Janvier 2008
    Messages : 1 159
    Par défaut
    merci j'ai effectué les modification mais la page 2 reste toujours vide sans passage de variable.

    voici la page :

    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
     
    $mots_f=$_POST['search-category'];
    $ville_f=$_POST['search-city'];
     
     
     
    /*si variable exist*/
     
    if(isset($mots_f)and ($ville_f))
    { 
     
    $lstAll=$managerServicePublic->countBySearchByVille($mots_f,$ville_f);
     
    	/*si c'est numerique c'est un code postal qui est recherché*/
    if (is_numeric($ville_f))
    {
    	$nbElements=$managerServicePublic->countBySearchByCp($mots_f,$ville_f);
     
    }	/*sinon c'est une ville qui est recherché*/
    else
    {
    	$nbElements=$managerServicePublic->countBySearchByVille($mots_f,$ville_f);	
     
    }	
     
    }
     
     
    // si on a déjà initialiser nos variables (premières page) alors pas besoin 
    if(empty($mots_f) || empty($ville_f))
    {
        // si on est ici c'est que forécement nos paramètres sont dans l'url
        $mots_f = (!empty($_GET['mot']) ? $_GET['mot'] : '');
        $ville_f = (!empty($_GET['ville']) ? $_GET['ville'] : '');
    }
     
     
     
     
     
    /*affichage apres recherche formulaire*/
     
    							if(isset($_POST['search-category']))
    							{
     
     
    							$lstAll=$managerServicePublic->getListBySearch($debut,12,$mots_f,$ville_f);
     
     
    							if(!empty($lstAll))
    							{
    								/*si tableau pas vide*/
    							foreach($managerServicePublic->getListBySearch($debut,12,$mots_f,$ville_f) as $lstAll) 
    								{
     
    									$body.='
     
    									<div class="col-md-3">
    										<a href="?sub='.$lstAll->getPivotLocal().'&id='.$lstAll->getIdServicePublic().'">
    											<div class="list-mig-like-com com-mar-bot-30">
     
    												<div class="list-mig-lc-con">
     
    													<p style="color:white;font-size:1.0em;">'.$lstAll->getNomServicePublic().'</p>
    													<p style="color:white;font-size:1.0em;">'.$lstAll->getCodePostal().'</p>
    												</div>
    											</div>
    										</a>
    									</div>
    									';
     
     
    								}
     /* On calcule le numéro du premier élément à récupérer */
    // si on a une page et que c'est un entier alors ok si on initialise à 1
     
    $page = (!empty($_GET['page']) && is_int($_GET['page'])) ? $_GET['page'] : 1;
    $debut = ($page - 1) * 12;		
    $nbElements = $managerServicePublic->countDistinctNomServicePublic();
    $PaginationFinal = new Pagination();
    $PaginationFinal->setInnerLinks(12);
    $PaginationFinal->setNbElementsInPage(12);
    $PaginationFinal->setNbMaxElements($nbElements);
    $paginationFinal = $PaginationFinal->renderBootstrapPagination($mots_f,$ville_f);
     
    										$body.='
    										<br /><br />
    										<div class="center">
     
     
    										'.$paginationFinal.'
     
    										</div>
     
    									<br />';
    							}
    							else
    								{
     
    									$body.='<p>Aucun résultat trouvé.</p>';
    								}
    							}
    quand je survol page 2 je ne vois pas les variable dans l'url juste page=2.

    merci

  15. #15
    Membre Expert

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 583
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 583
    Par défaut
    Tu dois donc placer des var_dump ou autre pour voir si les fonctions ou variable on bien ce que tu veux.
    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
     private function generateArrayPagination(string $mots_f = "", string $ville_f = "") {
            $array_pagination = array();
            $keyArray = 0;
     
            $subLinks = $this->currentPage - $this->innerLinks;
            $nbLastLink = ceil($this->nbMaxElements / $this->nbElementsInPage);
     
            if ($this->currentPage > 1) {
                // on ajoute nos paramètres à l'url
                $array_pagination[$keyArray++] = '<a href="' . str_replace('{i}', 1, $this->url) . '&ville=' .$ville_f. '&mot=' . $mots_f. '">1</a>';
            }
            if ($subLinks > 2) {
                $array_pagination[$keyArray++] = $this->linksSeparator;
            }
            for ($i = $subLinks; $i < $this->currentPage; $i++) {
               // à modifier n ajoutant les paramètres
                if ($i >= 2) {
                    $array_pagination[$keyArray++] = '<a href="' . str_replace('{i}', $i, $this->url) .  '&ville=' .$ville_f. '&mot=' . $mots_f. '" '">' . $i . '</a>';
                }
            }
    echo '<pre>';var_dump($array_pagination, $this->currentPage);echo '</pre>';
    }
    Si tu n'a pas les variables en url c'est que la fonction les ajoutes mal. J'aurais à la fin de la fonction fait un var_dump() de l'array pour voir ce qu'il ce passe.

Discussions similaires

  1. [PDO] LOAD DATA LOCAL INFILE avec PDO MySql
    Par ultimus dans le forum PHP & Base de données
    Réponses: 1
    Dernier message: 01/07/2015, 11h54
  2. [MySQL] Class pagination avec problème d'affichage
    Par eltyty dans le forum PHP & Base de données
    Réponses: 11
    Dernier message: 09/07/2011, 11h48
  3. Pagination avec PHP et Mysql
    Par __fabrice dans le forum Flash
    Réponses: 2
    Dernier message: 27/09/2006, 14h17
  4. Problème avec classe MySQL
    Par shadeoner dans le forum Requêtes
    Réponses: 1
    Dernier message: 10/07/2006, 11h25
  5. Réponses: 6
    Dernier message: 15/05/2005, 14h11

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