Hey all
I have some code to handle the paging for my news system, but i gotten alot of pages now, and would like to limit it, to maybe 20 or so, or make it so only the first 10 show and then the last 5 like this:
<< 1 2 3 4 5 6 7 8 9 10 ............ 50 51 52 53 55 >>
The thing is i can't quite figure out how to do it.
here is the code i use
<?php
$pr_side = 6;
$antal = mysql_result(mysql_query("SELECT COUNT(*) FROM news_posts"),0) or die(mysql_error());
$show = (isset($_GET["showfrom"]) && is_numeric($_GET["showfrom"]) && $_GET["showfrom"] < $antal) ? $_GET["showfrom"] : 0;
$result = mysql_query("SELECT * FROM news_posts ORDER BY post_id desc limit $show, $pr_side") or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
$topic = $row['post_topic'];
//and so on
echo"my news output is here";
}
if ($show > 0) {
$back= $show - $pr_side;
echo "<a href=\"$_SERVER[PHP_SELF]?showfrom=$back\" class=\"page\"><<</b></a>";
}
$page = 1;
for ($start = 0; $antal > $start; $start = $start + $pr_side) {
if($show != $page * $pr_side - $pr_side) {
echo "<a href=\"$_SERVER[PHP_SELF]?showfrom=$start\" class=\"page\"><b>$page</b></a>";
} else {
echo $page." ";
}
$page++;
}
if ($show < $antal - $pr_side) {
$next = $show + $pr_side;
echo "<a href=\"$_SERVER[PHP_SELF]?showfrom=$next\" class=\"page\"><b>>></b></a>
?>
I hope some one will / can help me with this.