Jump to content

Table Row counter, a bit stuck


Salis

Recommended Posts

Well, I am a little stuck here, my code works, like a charm; however there is only one problem.

Well I am writing a guestbook and I must say, it's coming along very nicely. I have writen a bit of code that fetched the numbers of row with a give page id then returns posts along with pages, 10 per page. Ok this is working great, but if I have 200 posts, well that's 20 pages and I don't want Page 1 | Page 2 and so on to 20. Instead I'd like "Page 1" to 5 then a .... "Page 15" and so on, but this is the part I cannot figure out. This is what I have so far:

[code]$result = mysql_query("SELECT * FROM posts WHERE page_id='$id'", $con);

$num = mysql_num_rows($result);
echo "There are $num posts on ";

$page_ct = $num / 10;
$page_ct = ceil($page_ct);
echo "$page_ct pages.<br>";

for($i=1;$i<=$page_ct;$i++)
{
if(!$i)
{
}
else
{
if($_GET['page']==$i)
{
echo "$i | ";
}
else
{
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">Page $i</a> | ";
}
}
}[/code]

If any one can help please do and thanks for the help.

An example can be found at http://lsfclan.com/1/
Link to comment
https://forums.phpfreaks.com/topic/16619-table-row-counter-a-bit-stuck/
Share on other sites

Ok. I have reread and worked with is code for a bit. It's good, mine is similar. But lets say I have 100 pages. Well that would take up a lot of screen and look very unsightly. Is there any code any one here can direct me to display something like this:

There are 937 posts on 94 pages: You are on Page 34
[u]<<Back[/u]: Page: [u]32[/u] [u]33[/u] 34 [u]35[/u] [u]36[/u] ... [u]46[/u] [u]86[/u] [u]94[/u] :[u]Next>>[/u]

I can get the total post and display the page links. I can't; however, get the "... [u]46[/u] [u]86[/u] [u]94[/u]" This is my challenge and this somethig that would be nice to overcome.

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.