pagina nummering (functie)
Auteur: DRUNK - 03 september 2004 - 01:01 - Gekeurd door: Dennisvb - Hits: 4071 - Aantal punten: 2.83 (3 stemmen)
zat een beetje te spelen kwam tot de volgende functie, mischien wel handig. Ben er niet zeker van of dit nou de beste / makkelijkste manier is maar voor mij werkt dit heel handig.
|
Code: |
<?php
function page_count($page, $max_pp, $query, $page_counter) {
$photos = mysql_result(mysql_query($query),0);
$pages = ceil($photos / $max_pp);
$first_page = ($page == 1) ? 0 : 1;
$last_page = ($page == $pages) ? 0 : $pages;
$prev = ($page == 1) ? 0 : $page - 1;
$next = ($page == $pages) ? 0 : $page + 1;
$discount = ($page > $page_counter) ? $page_counter : $page - 1;
$count = ($page < $pages - $page_counter) ? $page_counter : $pages - $page;
for ($i = $page - $discount; $i <= $page + $count; $i++) {
$page_nr[] = $i;
}
return array($page, $prev, $next, $page_nr, $first_page, $last_page);
}
/* gebruik */
$get_rows = "SELECT COUNT(*) AS NUM FROM tabel WHERE iets = 'iets'";
$page = (!isset($_GET['page'])) ? 1 : $_GET['page'];
$pages = page_count($page, 10, $get_rows, 5);
$prev_lnk = ($pages[1] != 0) ? '<a href=?page='.$pages[1].'>'.$lang['link']['prev'].'</a>' : $lang['link']['prev'];
$next_lnk = ($pages[2] != 0) ? '<a href=?page='.$pages[2].'>'.$lang['link']['next'].'</a>' : $lang['link']['next'];
$first = ($pages[4] != 0) ? '<a href=?page='.$pages[4].'>'.$lang['link']['first'].'</a>' : $lang['link']['first'];
$last = ($pages[5] != 0) ? '<a href=?page='.$pages[5].'>'.$lang['link']['last'].'</a>' : $lang['link']['last'];
$page_numbers = '';
for ($i = 0; $i <= count($pages[3]) - 1; $i++) {
$page_numbers .= ($pages[0] == $pages[3][$i]) ? '<b>['.$pages[3][$i].']</b>' : '<a href="?page='.$pages[3][$i].'">['.$pages[3][$i].']</a>';
}
?>
<?php function page_count($page, $max_pp, $query, $page_counter) { $pages = ceil($photos / $max_pp); $first_page = ($page == 1) ? 0 : 1; $last_page = ($page == $pages) ? 0 : $pages; $prev = ($page == 1) ? 0 : $page - 1; $next = ($page == $pages) ? 0 : $page + 1; $discount = ($page > $page_counter) ? $page_counter : $page - 1; $count = ($page < $pages - $page_counter) ? $page_counter : $pages - $page; for ($i = $page - $discount; $i <= $page + $count; $i++) { $page_nr[] = $i; } return array($page, $prev, $next, $page_nr, $first_page, $last_page); } /* gebruik */ $get_rows = "SELECT COUNT(*) AS NUM FROM tabel WHERE iets = 'iets'"; $page = (!isset($_GET['page'])) ? 1 : $_GET['page']; $pages = page_count($page, 10, $get_rows, 5); $prev_lnk = ($pages[1] != 0) ? '<a href=?page='.$pages[1].'>'.$lang['link']['prev'].'</a>' : $lang['link']['prev']; $next_lnk = ($pages[2] != 0) ? '<a href=?page='.$pages[2].'>'.$lang['link']['next'].'</a>' : $lang['link']['next']; $first = ($pages[4] != 0) ? '<a href=?page='.$pages[4].'>'.$lang['link']['first'].'</a>' : $lang['link']['first']; $last = ($pages[5] != 0) ? '<a href=?page='.$pages[5].'>'.$lang['link']['last'].'</a>' : $lang['link']['last']; $page_numbers = ''; for ($i = 0; $i <= count($pages[3]) - 1; $i++) { $page_numbers .= ($pages[0] == $pages[3][$i]) ? '<b>['.$pages[3][$i].']</b>' : '<a href="?page='.$pages[3][$i].'">['.$pages[3][$i].']</a>'; } ?>
Download code (.txt)
|
|
Stemmen |
Niet ingelogd. |
|