dezkit Posted September 28, 2008 Share Posted September 28, 2008 Hello, how do i make a pagination out of this? <?php $i=1; while($i<=100) { echo $i; echo "<br>"; $i++; } ?> Thanks all P.S. Google does not work. Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 28, 2008 Share Posted September 28, 2008 Your question is unanswerable. I suggest you re-think your problem and explain it in much greater detail. Quote Link to comment Share on other sites More sharing options...
waynew Posted September 28, 2008 Share Posted September 28, 2008 <?php $i=1; echo 'Pages: '; while($i<=100) { echo '<a href="example.php?page='.$i.'">'.$i.'</a> '; $i++; } ?> Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 28, 2008 Share Posted September 28, 2008 This is an old script I created when I started out in PHP <?php $page = (isset($_GET['page'])) ? $_GET['page'] : 0; $content = "Hello, World! {newpage} Hey! A new page... {newpage} Kool {newpage} Another too! {newpage} Umm, bye!"; $pages = explode('{newpage}', $content); echo $pages[$page].'<br>'; $total_pages = count($pages); $prevpage = $page - 1; $nextpage = $page + 1; if ($page > 0) { if($page < $total_pages - 1) { $page_div = ' | '; } else { $page_div = ''; } echo "<a href=\"?page={$prevpage}\">Prev</a>{$page_div}"; } if ($nextpage < $total_pages) { echo "<a href=\"?page={$nextpage}\">Next</a>"; } ?> Quote Link to comment Share on other sites More sharing options...
dezkit Posted September 28, 2008 Author Share Posted September 28, 2008 Your question is unanswerable. I suggest you re-think your problem and explain it in much greater detail. I literally just laughed at myself. This is what i mean: How do i make a pagination out of that, so that each page displays 10 numbers, and there are 10 pages Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 28, 2008 Share Posted September 28, 2008 Dont know if you saw my post above ^^^ Quote Link to comment Share on other sites More sharing options...
dezkit Posted September 28, 2008 Author Share Posted September 28, 2008 Ahhh yeah, that is just what i want, but, i need it to have a while loop to up to 1000 numbers? Thankss Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 28, 2008 Share Posted September 28, 2008 Ahhh yeah, that is just what i want, but, i need it to have a while loop to up to 1000 numbers? Thankss Change $content = "Hello, World! {newpage} Hey! A new page... {newpage} Kool {newpage} Another too! {newpage} Umm, bye!"; $pages = explode('{newpage}', $content); echo $pages[$page].'<br>'; to $content = range(1, 1000); $pages = array_chunk($content, 25); echo implode('<br />', $pages[$page]).'<hr>'; Quote Link to comment Share on other sites More sharing options...
dezkit Posted September 28, 2008 Author Share Posted September 28, 2008 That, works perfectly, thanks soo much wildteen <3 Quote Link to comment Share on other sites More sharing options...
dezkit Posted September 28, 2008 Author Share Posted September 28, 2008 Wait but is there a way to display Page numbers instead of "Next | Prev" ? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 28, 2008 Share Posted September 28, 2008 Yes. You could use a for loop for this. Eg: for($i = 0; $i < $total_pages; $i++) { echo ' <a href="?page='.$i.'">'.($i+1).'</a> |'; } Have a guess where it should go. Quote Link to comment Share on other sites More sharing options...
dezkit Posted September 28, 2008 Author Share Posted September 28, 2008 nevermind Quote Link to comment Share on other sites More sharing options...
dezkit Posted September 28, 2008 Author Share Posted September 28, 2008 Lol where does it go 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.