seularts Posted May 23, 2008 Share Posted May 23, 2008 i want to make this code: <?php if(file_exists('wr/events.php')){ $file = array_reverse( file( 'wr/events.php' ) ); foreach ( $file as $line ){ echo "$line\n"; } }else{ echo "File doesn't exist"; } ?> read from the events.php 10 items and then count the bext 10 items in a new page(same page) by pressing next! Link to comment https://forums.phpfreaks.com/topic/106966-paging/ Share on other sites More sharing options...
.josh Posted May 23, 2008 Share Posted May 23, 2008 the keyword you are looking for is "pagination" Link to comment https://forums.phpfreaks.com/topic/106966-paging/#findComment-548289 Share on other sites More sharing options...
seularts Posted May 24, 2008 Author Share Posted May 24, 2008 It seems that pagination is for interacting with data bases.. and i`m reading from a simple file.. so can anyone give me some code to patch my own in order to get some pagination on the page? Link to comment https://forums.phpfreaks.com/topic/106966-paging/#findComment-548779 Share on other sites More sharing options...
seularts Posted May 24, 2008 Author Share Posted May 24, 2008 Anyone!? Link to comment https://forums.phpfreaks.com/topic/106966-paging/#findComment-548805 Share on other sites More sharing options...
seularts Posted May 24, 2008 Author Share Posted May 24, 2008 Ok i managed to do this: <?php if(file_exists('wr/bands.php')){ $file = array_reverse( file( 'wr/bands.php' ) ); foreach ( $file as $line ){ } }else{ echo '<p class="form"> No content can be displayed yet!</o>'; } $page = (int)$_GET['page_number']; $lines_per_page = 10; $start = $page * $lines_per_page; $end = $start + $lines_per_page; for ($i = $start; $i < $end; $i++) echo $file[$i]; echo '<br /><a href="bands.php?page_number=' . ($page + 1) . '">Next page</a>'; ?> the problem is that the pages won't stop where the lines stop, so if i have 20 items and i show 10 pe page, there won't just be 2 pages.. i just keeps going pagining, can anyone give me a hint!? Link to comment https://forums.phpfreaks.com/topic/106966-paging/#findComment-548846 Share on other sites More sharing options...
Darklink Posted May 24, 2008 Share Posted May 24, 2008 If I'm hearing you right, your saying it won't stop saying Next Page when it reaches the last page. But that's because you haven't added anything to tell it to stop. <?php if ( $end < count($file) ) { echo "<a href=\"bands.php?page_number=" . ($page + 1) . "\">Next page</a>"; } ?> Link to comment https://forums.phpfreaks.com/topic/106966-paging/#findComment-548853 Share on other sites More sharing options...
seularts Posted May 24, 2008 Author Share Posted May 24, 2008 that is exactly what i was looking for.. thanks:) Link to comment https://forums.phpfreaks.com/topic/106966-paging/#findComment-548856 Share on other sites More sharing options...
.josh Posted May 24, 2008 Share Posted May 24, 2008 It seems that pagination is for interacting with data bases.. and i`m reading from a simple file.. so can anyone give me some code to patch my own in order to get some pagination on the page? pagination is the act of breaking down a list into separate pages. Yes, it is most commonly used with databases, but it doesn't matter where the data comes from. Glad you got it all sorted out. Link to comment https://forums.phpfreaks.com/topic/106966-paging/#findComment-548858 Share on other sites More sharing options...
seularts Posted May 24, 2008 Author Share Posted May 24, 2008 One last thing.. how can i make the prevoius link work proprealy? <?php if(file_exists('wr/bands.php')){ $file = array_reverse( file( 'wr/bands.php' ) ); foreach ( $file as $line ){ } }else{ echo '<p class="form"> No content can be displayed yet!</o>'; } $page = (int)$_GET['page_number']; $lines_per_page = 10; $start = $page * $lines_per_page; $end = $start + $lines_per_page; for ($i = $start; $i < $end; $i++) echo $file[$i]; if ( $end < count($file) ) { echo "<a href=\"bands.php?page_number=" . ($page + 1) . "\">Next page</a>"; } if ( $end > count($file) && $start < count($file)) { echo "<a href=\"bands.php?page_number=" . ($page - 1) . "\">Previous page</a>"; } ?> it just shows only on the last page of products, how can i make it go back from page x to page 1, ofcourse in page not beeing displayed this link? Link to comment https://forums.phpfreaks.com/topic/106966-paging/#findComment-548862 Share on other sites More sharing options...
sasa Posted May 24, 2008 Share Posted May 24, 2008 change line if ( $end > count($file) && $start < count($file)) to if ( $page > 0) Link to comment https://forums.phpfreaks.com/topic/106966-paging/#findComment-548953 Share on other sites More sharing options...
seularts Posted May 24, 2008 Author Share Posted May 24, 2008 Thanks alot.. that was exactly what i was looking for:) Link to comment https://forums.phpfreaks.com/topic/106966-paging/#findComment-548956 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.