PHP beginner |
|
Mysql?
Khad er ooit eens 1tje gemaakt om te oefennen.
Was gebasseerd op die va iemand anders die 'm gepost had in v1
<?
$page = (!isset($_GET['page'])) ? 1 : $_GET['page'];
//aantal records per pagina
$max = 20;
$start = ($max * $page) - $max;
//hier je gegevens van je mysql ophalen
while($var = mysql_fetch_array(mysql_query("SELECT * FROM table ORDER BY id LIMIT " . $start . ", " . $max . ""))) {
echo $var['id'];
}
//hier je aan jou mysql gegevens aanpassen
$rows = mysql_result(mysql_query("SELECT COUNT(id) FROM computers ORDER BY id"),0);
$pages = ceil($rows / $max);
if ($page > 1) {
$previous = $page - 1;
echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=" . $previous . "\"><<</a> ";
}
for ($i = 1; $i <= $pages; $i++) {
if ($page == $i) {
if ($i == $pages) {
echo "<b>" . $i . "</b> ";
} else {
echo "<b>" . $i . "</b>, ";
}
} else {
if ($i == $pages) {
echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=" . $i . "\">" . $i . "</a> ";
} else {
echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=" . $i . "\">" . $i . "</a>, ";
}
}
}
if ($page < $pages) {
$next = $page + 1;
echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=" . $next . "\">>></a>";
}
?>
<? $page = (!isset($_GET['page'])) ? 1 : $_GET['page']; //aantal records per pagina $max = 20; $start = ($max * $page) - $max; //hier je gegevens van je mysql ophalen } //hier je aan jou mysql gegevens aanpassen $pages = ceil($rows / $max); if ($page > 1) { $previous = $page - 1; echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=" . $previous . "\"><<</a> "; } for ($i = 1; $i <= $pages; $i++) { if ($page == $i) { if ($i == $pages) { echo "<b>" . $i . "</b> "; } else { echo "<b>" . $i . "</b>, "; } } else { if ($i == $pages) { echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=" . $i . "\">" . $i . "</a> "; } else { echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=" . $i . "\">" . $i . "</a>, "; } } } if ($page < $pages) { $next = $page + 1; echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=" . $next . "\">>></a>"; } ?>
|