Ok I use this script to get data from my database and split it into pages (so a lot of rows dont show up on just one page). Since there are a lot of rows, sometimes it goes up to 50 pages. I was wondering how I could make it show up like "1 2 3 4 5 6 7 8 9 10 ... 50" instead of 2 3 4 5 6 7 8 9 10 11 12 13 --> all the way to 50.
Here's my code:
$limit = $posts_limit; //defined in congfig.inc.php (25)
$query_count = "SELECT * FROM posts WHERE (topicid='$topicid') ORDER BY timestamp";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);
$PHP_SELF = $_SERVER['PHP_SELF'];
if(empty($page))
{
$page = 1;
}
$limitvalue = $page * $limit - ($limit);
$query = "SELECT * FROM posts,users WHERE (topicid='$topicid') AND username=name ORDER BY timestamp LIMIT $limitvalue, $limit";
$result = mysql_query($query) or die("Error: " . mysql_error());
if(mysql_num_rows($result) == 0)
{
echo("<center><b>Empty Post</b></center>");
}
while($row = mysql_fetch_array($result))
{
/////////////////
//posts here
/////////////////
if($page != 1)
{
$pageprev = $page - 1;
echo("<font size=1>Pages: </font>");
}
else
{
echo("<font size=1>Pages: </font>");
}
$numofpages = $totalrows / $limit;
for($i = 1; $i <= $numofpages; $i++)
{
if($i == $page)
{
echo("<font size=1>".$i."</font> ");
}
else
{
echo("<font size=1><a href='view.php?topicid=$topicid&page=$i'>$i</font></a> ");
}
}
$last_page=ceil ($totalrows/$limit);
if(($totalrows % $limit) != 0)
{
if($i == $page)
{
echo("<font size=1>" . $i . "</font> ");
}
else
{
echo("<a href='view.php?topicID=$topicID&page=$i'><font size=1>$i</font></a> ");
echo " ";
echo "<font size=1><a href=view.php?topicid=$topicid&page=$last_page#last>Last Page</a></font>";
}
}
if(($totalrows - ($limit * $page)) > 0)
{
$pagenext = $page + 1;
echo("<a href='$PHP_SELF?topicid=$topicid&page=$pagenext'><font size=1>>></font></a> ");
}
else
{
echo("");
}
Thanks in advance.