c-o-d-e Posted December 6, 2009 Share Posted December 6, 2009 I have a pagination script, which displays 10 results a page, and shows the page lists as << First [1] [2] [3] so on. I am not 100% sure it'll do << First [2] [3] [4] .. [15] (15 would be the last page) I would like results, lets say theres 15 pages.. to display like this. << First [2] [3] [4] .. [14] Last >> Also, if you click on << First, it'll be the first page, same for last. but with any [2] [3] so on- one of them pages.. to have a marker for that page. Lets say you clicked on [2], maybe the current page will turn red, or some sort of marker to let the user know what page there on. www.developers-community.com/allnews.php Use that link to see what I've got. If you click on page [2] the URL is &page=1 I would like to change it to &page=2, but a simple method would remove the first set of results. Can you help me on what to do? <?php include 'config.php'; $query = mysql_query("SELECT * FROM News ORDER BY Posted DESC") or trigger_error('Query failed: '. mysql_error()); $totalrows = mysql_num_rows($query); $numberofpages = ceil($totalrows / '10'); if(isset($_GET['page'])) { $currentpage = $_GET['page'] * 10; } else { $currentpage = 0; }; $query2 = mysql_query("SELECT * FROM News ORDER BY Posted DESC LIMIT $currentpage, 10 ") or trigger_error('Query failed: '. mysql_error()); $pages=0; $do=''; while($pages < $numberofpages) { if($pages==0){$do .= '<a href="allnews.php"><< First</a> ';}else{ $new = $pages++; $do .= '<a href="allnews.php?&page='.$new.'">['.$pages.']</a> ';}; $pages ++; } while($row = mysql_fetch_array($query2)) { echo '<h4 style="margin:0px; font-size:12px;">'. $row['Artname'] .'</h4>'; echo '<h4 style="margin:0px; font-size:11px;">'. $row['Posted'] .'</h4>'; echo '<p style="margin:0px;">'. $row['Article'] .'</p><br />'; } echo $do; ?> Thanks so much Quote Link to comment https://forums.phpfreaks.com/topic/184193-last-and-turning-page-2-page1-to-page2/ Share on other sites More sharing options...
greatstar00 Posted December 6, 2009 Share Posted December 6, 2009 <?php include 'config.php'; $query = mysql_query("SELECT * FROM News ORDER BY Posted DESC") or trigger_error('Query failed: '. mysql_error()); $totalrows = mysql_num_rows($query); $numberofpages = ceil($totalrows / '10'); if(isset($_GET['page'])) { $currentpage = $_GET['page'] * 10; } else { $currentpage = 0; }; $query2 = mysql_query("SELECT * FROM News ORDER BY Posted DESC LIMIT $currentpage, 10 ") or trigger_error('Query failed: '. mysql_error()); $pages=0; $do=''; while($pages < $numberofpages) { if($pages==0){$do .= '<a href="allnews.php"><< First</a> '; }else if($pages==$numberofpages-1){ $do .= '<a href="allnews.php?page='.$new.'">Last>></a> '; } else{ $new = $pages++; if($_GET['page']==$pages){ $do .= '<a href="allnews.php?&page='.$new.'"><font color="red">['.$pages.']</font></a> '; }else{ $do .= '<a href="allnews.php?&page='.$new.'">['.$pages.']</a> '; } }; $pages ++; } while($row = mysql_fetch_array($query2)) { echo '<h4 style="margin:0px; font-size:12px;">'. $row['Artname'] .'</h4>'; echo '<h4 style="margin:0px; font-size:11px;">'. $row['Posted'] .'</h4>'; echo '<p style="margin:0px;">'. $row['Article'] .'</p><br />'; } echo $do; ?> //so, add the similar stuff to <<first, and Last>>, see the middle pages as reference Quote Link to comment https://forums.phpfreaks.com/topic/184193-last-and-turning-page-2-page1-to-page2/#findComment-972472 Share on other sites More sharing options...
c-o-d-e Posted December 6, 2009 Author Share Posted December 6, 2009 Thanks, that helped a bunch. Quote Link to comment https://forums.phpfreaks.com/topic/184193-last-and-turning-page-2-page1-to-page2/#findComment-972486 Share on other sites More sharing options...
c-o-d-e Posted December 6, 2009 Author Share Posted December 6, 2009 Sorry about the "bump" I did more tests out with the code you gave me greatstar00 I have 27 "posts" which should display.. 10 each page, last page would display 7. I believe it should look like.. << First [2] Last >> Instead it doesn't have the "Last >>" Use the link at the beginning of the topic to preview it. Whats the problem? Quote Link to comment https://forums.phpfreaks.com/topic/184193-last-and-turning-page-2-page1-to-page2/#findComment-972495 Share on other sites More sharing options...
greatstar00 Posted December 6, 2009 Share Posted December 6, 2009 change $new = $pages++; to $new = $pages+1; because the one u got, it will increment $pages as well it is like this, for the one u have $new=$pages=$pages+1 Quote Link to comment https://forums.phpfreaks.com/topic/184193-last-and-turning-page-2-page1-to-page2/#findComment-972498 Share on other sites More sharing options...
c-o-d-e Posted December 6, 2009 Author Share Posted December 6, 2009 Ok, so I have something like this while($pages < $numberofpages){ if($pages==0){$do .= '<a href="allnews.php"><< First</a> '; } else if($pages==$numberofpages-1){ $do .= '<a href="allnews.php?&page='.$new.'">Last >></a> '; }else{ $new = $pages+1; if($_GET['page']==$pages){ $do .= '<a href="allnews.php?&page='.$new.'"><font color="red">['.$pages.']</font></a>'; } else { $do .= '<a href="allnews.php?&page='.$new.'">['.$pages.']</a> '; } } $pages ++; } It comes out like this << First [1] Last >> First = Page 1 [1] = should be [2], but should display the 2nd page, but it displays page 3. Last = displays page 3 Use the link, page [1] and Last are the same. When I have 27 results with a maximum of 10 a page. Quote Link to comment https://forums.phpfreaks.com/topic/184193-last-and-turning-page-2-page1-to-page2/#findComment-972514 Share on other sites More sharing options...
greatstar00 Posted December 6, 2009 Share Posted December 6, 2009 $pages=1; $do=''; while($pages <= $numberofpages){ if($pages==0){ $do .= '<a href="allnews.php"><< First</a> '; } else if($pages==$numberofpages){ $do .= '<a href="allnews.php?&page='.$new.'">Last >></a> '; }else{ $new = $pages; if($_GET['page']==$pages){ $do .= '<a href="allnews.php?&page='.$new.'"><font color="red">['.$pages.']</font></a>'; } else { $do .= '<a href="allnews.php?&page='.$new.'">['.$pages.']</a> '; } } $pages ++; } Quote Link to comment https://forums.phpfreaks.com/topic/184193-last-and-turning-page-2-page1-to-page2/#findComment-972523 Share on other sites More sharing options...
c-o-d-e Posted December 6, 2009 Author Share Posted December 6, 2009 Sorry, you editted previous post, after I made the changes, I'll try it. I tried it and it comes up like this now << First [1] [2] Last >> [2] is the same as Last. Quote Link to comment https://forums.phpfreaks.com/topic/184193-last-and-turning-page-2-page1-to-page2/#findComment-972527 Share on other sites More sharing options...
c-o-d-e Posted December 7, 2009 Author Share Posted December 7, 2009 Sorry for the little bump. This is very complicated, if you can figure it out, let me know. Otherwise, how will I edit the first code, to make it .. [1] [2] [3] [4] [5] (5 being the last page, 1 being the first) but for example, for the current page, it'll be marked in red. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/184193-last-and-turning-page-2-page1-to-page2/#findComment-972616 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.