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
| <?php
define('NB_PAR_PAGE', 10);
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
$article = simplexml_load_file('pagination_simplexml.xml');
$count = count($article->xpath('//annonce'));
if ($count > 0) {
$debut_pos = ($page - 1) * NB_PAR_PAGE + 1;
$fin_pos = $page * NB_PAR_PAGE + 1;
$derniere_page = ceil($count / NB_PAR_PAGE);
$annonces = $article->xpath("//annonce[position()>=$debut_pos and position()<$fin_pos]");
foreach ($annonces as $annonce) {
echo (string) $annonce->model . '<br/>';
}
if ($page > 1) {
echo '<a href="' . basename(__FILE__) . '?page=' . ($page - 1) . '">Page précédente</a>';
}
for ($i = 1; $i <= $derniere_page; $i++) {
if ($i == $page) {
echo '<b>' . $i . '</b>';
} else {
echo '<a href="' . basename(__FILE__) . '?page=' . $i . '">' . $i . '</a>';
}
}
if ($page < $derniere_page) {
echo '<a href="' . basename(__FILE__) . '?page=' . ($page + 1) . '">Page suivante</a>';
}
}
?> |
Partager