Jump to content

Archived

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

Salis

Table Row counter, a bit stuck

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/

Share this post


Link to post
Share on other sites
Hope the following tutorial on this can shed some light:

[url=http://www.php-mysql-tutorial.com/php-mysql-paging.php]http://www.php-mysql-tutorial.com/php-mysql-paging.php[/url]

Share this post


Link to post
Share on other sites
Cool, that helped a little, but i still need to do something like this

Goto page 1, 2, 3 ... 30, 31, 32  Next

Share this post


Link to post
Share on other sites
Your have to read the tutoral and set the number of descripion to palce on the page.

if you show 10 per page then page 2 will be 10 - 20 so on ok.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
$_GET['page'];
echo $page;

i think the number is in the url so try this ok.

Share this post


Link to post
Share on other sites

×

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.