Salis Posted August 5, 2006 Share Posted August 5, 2006 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/ Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted August 5, 2006 Share Posted August 5, 2006 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] Quote Link to comment Share on other sites More sharing options...
Salis Posted August 5, 2006 Author Share Posted August 5, 2006 Cool, that helped a little, but i still need to do something like thisGoto page 1, 2, 3 ... 30, 31, 32 Next Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 5, 2006 Share Posted August 5, 2006 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. Quote Link to comment Share on other sites More sharing options...
Salis Posted August 6, 2006 Author Share Posted August 6, 2006 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 Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 6, 2006 Share Posted August 6, 2006 $_GET['page'];echo $page;i think the number is in the url so try this ok. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.