RalphLeMouf Posted August 30, 2011 Share Posted August 30, 2011 Hello- I have a social network that has a blogs and questions section. There are community pages for each one ( blogs/questions ) On each of those pages. the first ten blogs/questions are displayed. To the right of those are a list of clickable categories that sort the pages according to their category. I have pagination implemented after each ten. I am doing a mod_rewrite for pretty urls on my dev and have everything working correctly. The problem is, after hitting next the first time 'page=' is blank and just reloads the first (defaulted page) but after a second click it becomes 'page=10' as it should and then the third click 'page=20" as it should. So basically I am trying to get it to go to 'page=10" after one click, not two. Here is the code for the pagination: <div id="all_page_turn"> <ul> <?php if($totalBlogs > 10 && $_GET['page'] >= 10) { ?> <li class="PreviousPageBlog round_10px"> <a href="/blogs/?cat=<?php if(isset($_GET['cat'])) { echo $_GET['cat'];} ?>&sort=<?php if(isset($_GET['sort'])) { echo $_GET['sort'];} ?>&page=<?php if(isset($_GET['page'])) { echo ($_GET['page'] - 10);} ?>">Previous Page</a> </li> <?php } ?> <?php if($totalBlogs > 10 && $_GET['page'] < ($totalBlogs-10)) { ?> <li class="NextPageBlog round_10px"> <a href="/blogs/?cat=<?php if(isset($_GET['cat'])) { echo $_GET['cat'];} ?>&sort=<?php if(isset($_GET['sort'])) { echo $_GET['sort'];} ?>&page=<?php if(isset($_GET['page'])) { echo ($_GET['page'] + 10);} ?>">Next Page</a> </li> <?php } ?> </ul> </div> </div> and here is the defaulted category link: <div id="RightBlogs"> <div id="search_blogs_future" class="round_10px"> <form name="searchBlogs" action="/blogs" method="get"> <input type="text" name="BlogSearch" class="text" value="<?php if(empty($_GET['BlogSearch'])) { echo "Search Blogs"; }else{ echo $_GET['BlogSearch'];} ?>" onclick="clearify(this);" /> <input type="submit" name="subBlogSearch" value="Search" /> </form> </div> <div class='<?php if(empty($_GET['cat']) || $_GET['cat'] == "All") { echo "all_blog_cats_Highlighted"; }else{ echo "all_blog_cats_unHighlighted"; } ?> round_10px'> <a href='/blogs/?cat=All'> All </a> </div> Here is a screen shot of the page, as I'm on my dev so I can't provide a link. you can't see the "next" button, but it's there on the bottom, and then the categories are on the right. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/246048-pulling-page-count-in-url-pagination/ Share on other sites More sharing options...
jcbones Posted August 31, 2011 Share Posted August 31, 2011 On the first page load, $_GET['page'] is probably NOT defined, proper de-bugging would reveal that. You should be setting NEXT to a default value, before setting the URL. $page = (isset($_GET['page']) && $_GET['page'] >= 10) ? $_GET['page'] : 10; Quote Link to comment https://forums.phpfreaks.com/topic/246048-pulling-page-count-in-url-pagination/#findComment-1263760 Share on other sites More sharing options...
WebStyles Posted August 31, 2011 Share Posted August 31, 2011 Just a comment: So basically I am trying to get it to go to 'page=10" after one click, not two. Here is the code for the pagination: "page 10 after 1 click"? I would expect page 2. You seem to be counting articles/posts and not pages, but even then, if you display 10 at each time, then the next page would start with article 11, and not 10... Having the correct page number in the url is sometimes useful for users to jump between pages just by changing the number (I know I do that a lot on other sites). Having page 10, 20, 30, 40 will mislead the user into thinking there are a lot of pages in between that he's not seeing. Also, if you mean 'article' instead of page, you should probably rename your variables so that they make sense. Quote Link to comment https://forums.phpfreaks.com/topic/246048-pulling-page-count-in-url-pagination/#findComment-1263881 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.