Jump to content

Recommended Posts

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

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

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

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.