xoligy Posted September 14, 2008 Share Posted September 14, 2008 Ok thought i just fixed this but seems i was also copying every post 3x lol Basically everything is set up but here is the problem i want it to display the numbers 1,2,3...99, 100, 101 but without disrupting how many items per page are displayed so if i have 700posts i should have 10 pages and the pagination will look like 1, 2, 3...8, 9, 10 but how it is is 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 anyhow here is the code: <? $query = mysql_query("SELECT * FROM $tab[forum_post] WHERE topic_id=$topicid ORDER BY post_id LIMIT $start, $itemperpage"); $this_page = mysql_num_rows($query) or die("No post records found!"); $paging = generate_pagination("viewtopic.php?topicid=$topicid", $all_record, $itemperpage, $start, $tru); ?> Quote Link to comment https://forums.phpfreaks.com/topic/124165-solved-pagination/ Share on other sites More sharing options...
.josh Posted September 14, 2008 Share Posted September 14, 2008 You need to post what's in generate_pagination for us to give you any kind of specific help. But overall, you just need to find the loop that generates the numbers (I'm assuming it's in generate_pagination), and alter it. Instead of just doing a generic for ($x = 1;$x < $pages; $x++) { ... } you could do several things. One thing you could do is do two separate loops; one for the 1,2,3 and another for the 8,9,10. Or you could make a condition inside your loop to only display the numbers you want, like for ($x = 1;$x < $pages; $x++) { if (($x < 4) && ($x > ($pages - 4))) { // display page numbers here } } Quote Link to comment https://forums.phpfreaks.com/topic/124165-solved-pagination/#findComment-641092 Share on other sites More sharing options...
xoligy Posted September 14, 2008 Author Share Posted September 14, 2008 I ended up sorting it i was trying to change the data in the wrong file yet again *sugh* thanks anyway crayon Quote Link to comment https://forums.phpfreaks.com/topic/124165-solved-pagination/#findComment-641103 Share on other sites More sharing options...
xoligy Posted September 14, 2008 Author Share Posted September 14, 2008 Well im back i did get the pagination working how i wanted by changing if ($total_pages > 10){ to 5 but now i have this display issue "Prev 1, 2, 3, , 4, 5, 6 Next" or this one "Prev 1, 2, 3 ... , 6, 7, 8 Next" (depends on how many pages there are. function generate_pagination($base_url, $num_items, $per_page, $start_item, $tru, $add_prevnext_text = TRUE) { $total_pages = ceil($num_items/$per_page); if ( $total_pages == 1 ) { return ""; } $on_page = floor($start_item / $per_page) + 1; $page_string = ""; if ( $total_pages > 5 ) { $init_page_max = ( $total_pages > 3 ) ? 3 : $total_pages; for($i = 1; $i < $init_page_max + 1; $i++) { $page_string .= ( $i == $on_page ) ? "<b>" . $i . "</b>" : "<a href=\"$base_url&tru=$tru&start=" . ( ( $i - 1 ) * $per_page ) . "\">" . $i . "</a>"; if ( $i < $init_page_max ) { $page_string .= ", "; } } if ( $total_pages > 3 ) { if ( $on_page > 1 && $on_page < $total_pages ) { $page_string .= ( $on_page > 5 ) ? " ... " : ", "; $init_page_min = ( $on_page > 4 ) ? $on_page : 5; $init_page_max = ( $on_page < $total_pages - 4 ) ? $on_page : $total_pages - 4; for($i = $init_page_min - 1; $i < $init_page_max + 2; $i++) { $page_string .= ($i == $on_page) ? "<b>" . $i . "</b>" : "<a href=\"$base_url&tru=$tru&start=" . ( ( $i - 1 ) * $per_page ) . "\">" . $i . "</a>"; if ( $i < $init_page_max + 1 ) { $page_string .= ", "; } } $page_string .= ( $on_page < $total_pages - 4 ) ? " ... " : ", "; } else { $page_string .= " ... "; } for($i = $total_pages - 2; $i < $total_pages + 1; $i++) { $page_string .= ( $i == $on_page ) ? "<b>" . $i . "</b>" : "<a href=\"$base_url&tru=$tru&start=" . ( ( $i - 1 ) * $per_page ) . "\">" . $i . "</a>"; if( $i < $total_pages ) { $page_string .= ", "; } } } } else { for($i = 1; $i < $total_pages + 1; $i++) { $page_string .= ( $i == $on_page ) ? "<b>" . $i . "</b>" : "<a href=\"$base_url&tru=$tru&start=" . ( ( $i - 1 ) * $per_page ) . "\">" . $i . "</a>"; if ( $i < $total_pages ) { $page_string .= ", "; } } } if ( $add_prevnext_text ) { if ( $on_page > 1 ) { $page_string = " <a href=\"$base_url&tru=$tru&start=" . ( ( $on_page - 2 ) * $per_page ) . "\">Prev</a> " . $page_string; } if ( $on_page < $total_pages ) { $page_string .= " <a href=\"$base_url&tru=$tru&start=" . ( $on_page * $per_page ) . "\">Next</a>"; } } return $page_string; } Quote Link to comment https://forums.phpfreaks.com/topic/124165-solved-pagination/#findComment-641232 Share on other sites More sharing options...
xoligy Posted September 14, 2008 Author Share Posted September 14, 2008 No one know whats up? Quote Link to comment https://forums.phpfreaks.com/topic/124165-solved-pagination/#findComment-641320 Share on other sites More sharing options...
.josh Posted September 14, 2008 Share Posted September 14, 2008 well i told you what you need to do in my previous post. Would you like me to write your code for you? Quote Link to comment https://forums.phpfreaks.com/topic/124165-solved-pagination/#findComment-641426 Share on other sites More sharing options...
xoligy Posted September 14, 2008 Author Share Posted September 14, 2008 Sorry but i admit i am an idiot Crayon lol Anyhow i believe i fixed the error with the following changes in the code: <? function generate_pagination($base_url, $num_items, $per_page, $start_item, $tru, $add_prevnext_text = TRUE) { $total_pages = ceil($num_items/$per_page); if ( $total_pages == 1 ) { return ""; } $on_page = floor($start_item / $per_page) + 1; $page_string = ""; if ( $total_pages > 5 ) { $init_page_max = ( $total_pages > 3 ) ? 3 : $total_pages; for($i = 1; $i < $init_page_max + 1; $i++) { $page_string .= ( $i == $on_page ) ? "<b>" . $i . "</b>" : "<a href=\"$base_url&tru=$tru&start=" . ( ( $i - 1 ) * $per_page ) . "\">" . $i . "</a>"; if ( $i < $init_page_max ) { $page_string .= ", "; } } if ( $total_pages > 3 ) { if ( $on_page > 1 && $on_page < $total_pages ) { $page_string .= ( $on_page > 4 ) ? " ... " : ", "; $init_page_min = ( $on_page > 3 ) ? $on_page : 6; $init_page_max = ( $on_page < $total_pages - 4 ) ? $on_page : $total_pages - 4; for($i = $init_page_min - 1; $i < $init_page_max + 2; $i++) { $page_string .= ($i == $on_page) ? "<b>" . $i . "</b>" : "<a href=\"$base_url&tru=$tru&start=" . ( ( $i - 1 ) * $per_page ) . "\">" . $i . "</a>"; if ( $i < $init_page_max + 1 ) { $page_string .= ", "; } } $page_string .= ( $on_page < $total_pages - 2 ) ? " ... " : ", "; } else { $page_string .= " ... "; } for($i = $total_pages - 2; $i < $total_pages + 1; $i++) { $page_string .= ( $i == $on_page ) ? "<b>" . $i . "</b>" : "<a href=\"$base_url&tru=$tru&start=" . ( ( $i - 1 ) * $per_page ) . "\">" . $i . "</a>"; if( $i < $total_pages ) { $page_string .= ", "; } } } } else { for($i = 1; $i < $total_pages + 1; $i++) { $page_string .= ( $i == $on_page ) ? "<b>" . $i . "</b>" : "<a href=\"$base_url&tru=$tru&start=" . ( ( $i - 1 ) * $per_page ) . "\">" . $i . "</a>"; if ( $i < $total_pages ) { $page_string .= ", "; } } } if ( $add_prevnext_text ) { if ( $on_page > 1 ) { $page_string = " <a href=\"$base_url&tru=$tru&start=" . ( ( $on_page - 2 ) * $per_page ) . "\">Prev</a> " . $page_string; } if ( $on_page < $total_pages ) { $page_string .= " <a href=\"$base_url&tru=$tru&start=" . ( $on_page * $per_page ) . "\">Next</a>"; } } return $page_string; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/124165-solved-pagination/#findComment-641503 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.