probleme de pagination php / js
Bonjour,
J'ai un souci de pagination avec mon code. Je voudrais afficher 10 lignes par page mais le résultat que j'obtiens est toujours de 3 lignes par pages.
Est ce que quelqu'un saurait d'où cela peut venir?
Voilà le code de la page:
Code:
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
|
<?php
class PS_Pagination {
var $php_self;
var $rows_per_page = 10; //Nombre de ligne par page
var $total_rows = 0; //Nb lignes retournées par la requete
var $links_per_page = 5; //Nombre de liens à afficher par page
var $append = ""; //Paramètres a ajouter aux liens
var $sql = "";
var $debug = true;
var $conn = false;
var $page = 1;
var $max_pages = 0;
var $offset = 0;
/**
* Constructor
*
* @param ressource $connection connection mysql
* @param string $sql requete
* @param integer $rows_per_page Nb de lignes à retourner par page.10 par défaut
* @param integer $links_per_page nb liens par page -> Défaut 5
* @param string $append paramètres à ajouter aux liens
*/
function PS_Pagination($connection, $sql, $rows_per_page = 10, $links_per_page = 5, $append = "") {
$this->conn = $connection;
$this->sql = $sql;
$this->rows_per_page = (int)$rows_per_page;
if (intval($links_per_page ) > 0) {
$this->links_per_page = (int)$links_per_page;
} else {
$this->links_per_page = 5;
}
$this->append = $append;
$this->php_self = htmlspecialchars($_SERVER['PHP_SELF'] );
if (isset($_GET['page'] )) {
$this->page = intval($_GET['page'] );
}
}
/**
* Execute la requete et initialise les variables
*
* @access public
* @return resource
*/
function paginate() {
//retourne le nb total de ligne
$all_rs = $this->conn->prepare( $this->sql );
$all_rs->execute();
if (! $all_rs) {
if ($this->debug)
echo "Erreur sur la requête sql.<br /><br />Erreur " . mysql_error();
return false;
}
$this->total_rows = $all_rs->rowCount();
//Retourne FALSE si pas de résultat
if ($this->total_rows == 0) {
if ($this->debug)
echo "Pas de données.";
return FALSE;
}
//Nb de pages max.
$this->max_pages = ceil($this->total_rows / $this->rows_per_page );
if ($this->links_per_page > $this->max_pages) {
$this->links_per_page = $this->max_pages;
}
//Si num de page invalide -> redirige vers page 1
if ($this->page > $this->max_pages || $this->page <= 0) {
$this->page = 1;
}
//Calcul OFFSET
$this->offset = ($this->page - 1) * $this->rows_per_page;
//retour result set
$query = $this->sql . " LIMIT {$this->offset}, {$this->rows_per_page}";
//$query = $this->sql . " LIMIT {$this->offset}, 10";
//debug query
echo $query;
$rs = $this->conn->prepare( $query );
$rs->execute();
if (! $rs) {
if ($this->debug)
echo " probleme avec la requete de pagination.<br /><br />Error: " . mysql_error();
return false;
}
return $rs;
} |
Code de l'affichage:
Code:
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
|
<?php
header('Content-type: text/html; charset=iso-8859-1');
//fetch.php
//include
include 'db_connect.php';
include 'pagination.php';
$sql = "SELECT
`bugs_activity`.`bug_id` AS `bug_id`,
`products`.`name` AS `client`,
`bugs`.`cf_platforme` AS `plateforme`,
`bugs_activity`.`bug_when` AS `bug_when`,
`bugs`.`product_id` AS `product_id`,
`bug_severity`.`id` AS `severity_id`,
`bugs`.`bug_severity` AS `severité`,
COUNT(*) AS count
FROM
`bugs_activity`,
`bug_severity`,
`bugs`,
`products`
WHERE
`bugs`.`product_id` = `products`.`id`
AND `bug_severity`.`value` = `bugs`.`bug_severity`
AND `bugs`.`bug_id` = `bugs_activity`.`bug_id`
AND `bugs_activity`.`bug_when` IS NOT NULL
AND `bugs_activity`.`added` = 'REOPENED'
AND `bugs_activity`.`bug_when` BETWEEN '2018-03-01' and '2018-05-30'
GROUP BY `bugs_activity`.`bug_id`
ORDER BY `bugs_activity`.`bug_id`, `bugs_activity`.`bug_when` ASC";
$pager = new PS_Pagination($conn, $sql, 3, 4, null);
$rs = $pager->paginate();
//calcul du nb de lignes que retourne la requete
$num = $rs->rowCount();
if($num >= 1 ){
echo "<table id=table_data class=data-table>";
echo "<thead>";
echo "<tr>";
echo "<th>BUG_ID</th>";
echo "<th>PRODUCT_ID</th>";
echo "<th>CLIENT</th>";
echo "<th>PLATEFORME</th>";
echo "<th>SEVERITY_ID</th>";
echo "<th>SEVERITE</th>";
echo "<th>DATE</th>";
echo "<th>NB_REOPENED</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while ($row = $rs->fetch(PDO::FETCH_ASSOC)){
echo "<tr class='data-tr' align='center'>";
echo "<td><a href=https://support.datalog-finance.com/show_bug.cgi?id={$row["bug_id"]}> {$row["bug_id"]}</a></td>";
echo "<td>{$row["product_id"]}</td>";
echo "<td>{$row["client"]}</td>";
echo "<td>{$row["plateforme"]}</td>";
echo "<td>{$row["severity_id"]}</td>";
echo "<td>{$row["severité"]}</td>";
echo "<td>{$row["bug_when"]}</td>";
echo "<td>{$row["count"]}</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
}else{
// si pas de données
echo "Pas de données disponible!";
}
echo "<div class='page-nav'>";
// Affiche n° de page
echo $pager->renderFullNav();
echo "</div>";
?> |
je pense que le probleme doit se situer dans ce bout de code mais je ne vois pas ce qui pourrait clocher dedans:
Code:
1 2 3 4 5 6 7 8 9 10
|
//Calcul OFFSET
$this->offset = ($this->page - 1) * $this->rows_per_page;
//retour result set
$query = $this->sql . " LIMIT {$this->offset}, {$this->rows_per_page}";
//$query = $this->sql . " LIMIT {$this->offset}, 10";
//debug query
echo $query;
$rs = $this->conn->prepare( $query );
$rs->execute(); |
merci pour votre aide,