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
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.