Jump to content


Photo

Table Row counter, a bit stuck


  • Please log in to reply
5 replies to this topic

#1 Salis

Salis
  • Members
  • PipPipPip
  • Advanced Member
  • 130 posts

Posted 05 August 2006 - 07:58 AM

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:

$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> | ";
		}
	}
}

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

An example can be found at http://lsfclan.com/1/

#2 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 05 August 2006 - 01:08 PM

Hope the following tutorial on this can shed some light:

http://www.php-mysql...ysql-paging.php

RTFM is an almost extinct art form, it should be subsidized.

#3 Salis

Salis
  • Members
  • PipPipPip
  • Advanced Member
  • 130 posts

Posted 05 August 2006 - 06:44 PM

Cool, that helped a little, but i still need to do something like this

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

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 05 August 2006 - 06:49 PM

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.


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 Salis

Salis
  • Members
  • PipPipPip
  • Advanced Member
  • 130 posts

Posted 06 August 2006 - 03:32 AM

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
<<Back: Page: 32 33 34 35 36 ... 46 86 94 :Next>>

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

Thanks

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 06 August 2006 - 07:17 AM

$_GET['page'];
echo $page;

i think the number is in the url so try this ok.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users