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. Link to comment https://forums.phpfreaks.com/topic/126185-pagination-without-database/ 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. Link to comment https://forums.phpfreaks.com/topic/126185-pagination-without-database/#findComment-652506 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++; } ?> Link to comment https://forums.phpfreaks.com/topic/126185-pagination-without-database/#findComment-652507 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>"; } ?> Link to comment https://forums.phpfreaks.com/topic/126185-pagination-without-database/#findComment-652511 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 Link to comment https://forums.phpfreaks.com/topic/126185-pagination-without-database/#findComment-652512 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 ^^^ Link to comment https://forums.phpfreaks.com/topic/126185-pagination-without-database/#findComment-652515 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 Link to comment https://forums.phpfreaks.com/topic/126185-pagination-without-database/#findComment-652519 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>'; Link to comment https://forums.phpfreaks.com/topic/126185-pagination-without-database/#findComment-652522 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 Link to comment https://forums.phpfreaks.com/topic/126185-pagination-without-database/#findComment-652524 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" ? Link to comment https://forums.phpfreaks.com/topic/126185-pagination-without-database/#findComment-652525 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. Link to comment https://forums.phpfreaks.com/topic/126185-pagination-without-database/#findComment-652531 Share on other sites More sharing options...
dezkit Posted September 28, 2008 Author Share Posted September 28, 2008 nevermind Link to comment https://forums.phpfreaks.com/topic/126185-pagination-without-database/#findComment-652532 Share on other sites More sharing options...
dezkit Posted September 28, 2008 Author Share Posted September 28, 2008 Lol where does it go Link to comment https://forums.phpfreaks.com/topic/126185-pagination-without-database/#findComment-652534 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.