Bonjour à tous,
j'ai un gros soucis avec une pagination.
Je tente de trouver le problème mais pas moyen d'identifier si une variable ou autre chose cause cela.
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
function pag_partenaires(){
		 /*** set the page name ***/
		 $page_name = htmlentities($_SERVER['PHP_SELF']);
 
		 /*** set the number of results per page ***/
		 $limit = 20;
 
		 /*** check the SESSION array for the total_records ***/
		 if(!isset($_SESSION['total_records']))
		 {
		    try
		    {
		        /*** first get the count of records ***/
 
		        $_SESSION['total_records'] = $this->dbParts->selectCountParts();
		    }
		    catch (Exception $e)
		    {
		        $_SESSION['total_records'] = 0;
		    }
		 }
		    /*** check for a page number in GET ***/
		    if( isset($_GET["page"]) == false)
		    {
		        /*** no page in GET ***/
		        $page = 1;
		    }
		    /*** if the page number is not an int or not within range, assign it to page 1 ***/
		     elseif(filter_var($_GET['page'], FILTER_VALIDATE_INT, array("min_range"=>1, "max_range"=>$_SESSION['total_records'])) == false)
		     {
		        $page = 1;
		    }
		    else
		    {
		        /*** if all is well, assign it ***/
		        $page = (int)$_GET['page'];
		    }
 
		 /*** if we have no results then there is no point in going on ***/
		 if($_SESSION['total_records'] == 0)
		 {
		    $content = 'No Records Available';
		 }
		 else
		 {
		    /*** feed the variables to the pager class ***/
		    $pager = Pagination::getPagerData($_SESSION['total_records'], $limit, $page);
 
		    /*** retrieve the variables from the pager class ***/
		    $offset = $pager->offset;
		    $limit  = $pager->limit;
		    $page   = $pager->page;
 
		    /*** begin the menu ***/
		    $menu = '';
 
		    /*** if this is page 1 there is no previous link ***/
		    if($page != 1)
		    {
		        $menu .= '<li><a href="'.$page_name.'?page='.($page - 1).'">&lt;&lt; PREV </a></li>';
		    }
 
		    /*** loop over the pages ***/
		    for ($i = 1; $i <= $pager->num_pages; $i++)
		    {
		        if ($i == $pager->page)
		        {
		            $menu .= '<li class="selected">'.$i.'</li>';
		        }
		        else
		        {
		            $menu .= '<li><a href="'.$page_name.'?page='.$i.'">'.$i.'</a></li>'."\n";
		        }
		    }
 
		    /*** if we are on the last page, we do not need the NEXT link ***/
		    if ($page < $pager->num_pages)  
		    {
		        $menu .= '<li><a href="'.$page_name.'?page='.($page + 1).'"> NEXT &gt;&gt;</a></li>';
		    }
 
		    /*** our sql statement ***/
		    $sql = 'SELECT * FROM partenaires WHERE sector_activity = :sector_activity LIMIT :limit OFFSET :offset';
		    /*** run the query ***/
			$res = $this->layer->select($sql,array(':sector_activity'=>$this->getSector,':limit'=>$limit,':$offset'=>$offset));
		    /*** the elements table content ***/
		    $content = '';
		    foreach ($res as $el)
		    {
		        $content .= '
		        <tr><td>'.$el['id'].'</td>
		        <td>'.$el['name'].'</td>
		        <td>'.$el['sitename'].'</td></tr>';
		    }
		 }
la fonction fautive du moins je pense :
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
public static function getPagerData($num_pages, $limit, $page){
	    /*** the number of pages ***/
	    $num_pages = ceil($num_pages / $limit);
	    $page = max($page, 1);
	    $page = min($page, $num_pages);
	    /*** calculate the offset ***/
	    $offset = ($page - 1) * $limit;
	    /*** a new instance of stdClass ***/
	    $ret = new stdClass;
 
	    /*** assign the variables to the return class object ***/
	    $ret->offset   = $offset;
	    $ret->limit    = $limit;
	    $ret->num_pages = $num_pages;
	    $ret->page     = $page;
	    /*** return the object ***/
	    return $ret;
	}
L'erreur retourne que la ligne 47 cause lle petit prob :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
$num_pages = ceil($num_pages / $limit);
Peut être aurai je du simplifier le code pour avoir un truc fonctionnel