nuttycoder Posted April 6, 2009 Share Posted April 6, 2009 am trying to get pagitnation working when reading lines from a text file, it works perfect when I set the limit to 1 to when I set the limit to 30 which would cause 30 lines per page only 18 are shown. I have a text file with numbers on each line : 1 2 3 ...ect going to 35 then the file is read using this code: <?php $emails = file("emails.txt"); //load all the emails into an array $limit = 30; //limit to 30 per page //Get the current page if(!isset($_GET['page'])) { $page = 1; } else { $page = $_GET['page']; } //Find out how many results there are $totalResults = count($emails); //Get the total pages $totalPages = ceil($totalResults / $limit); //If the page you are on is bigger then the totalPages then set the page to the totalPages if($page > $totalPages) { $page = $totalPages; } //Find out where to start looping from $from = ($page * $limit) - $limit; //Create a temp array $tmp_emails = array(); //Start looping for($i = $from; $i < $from + ceil($totalResults / $totalPages); $i++) { $tmp_emails[] = $emails[$i]; } //Implode the temp array, seperating the elements. echo implode(",<br/> ", $tmp_emails); echo "<p style=\"clear:both;\" align=\"center\">\n"; // Build Previous Link if($_GET['page'] > 1){ $prev = ($_GET['page'] - 1); echo "<a href=\"m.php?page=$prev\">Previous</a>\n "; } for($i = 1; $i <= $totalPages; $i++){ if(($_GET['page']) == $i || $page == $i) { if($totalPages > 1) { echo "$i\n "; } } else { echo "<a href=\"m.php?page=$i\">$i</a>\n "; } } // Build Next Link if($_GET['page'] < $totalPages){ $next = ($_GET['page'] + 1); echo "<a href=\"m.php?page=$next\">Next</a>\n"; } echo "</p>\n"; ?> not sure where am going wrong if someone could help me with this that would be great. Quote Link to comment https://forums.phpfreaks.com/topic/152798-solved-pagination-problem/ Share on other sites More sharing options...
mrMarcus Posted April 6, 2009 Share Posted April 6, 2009 is there something on line 18 that might cause the script to break/end? perhaps you should post the contents of the file. Quote Link to comment https://forums.phpfreaks.com/topic/152798-solved-pagination-problem/#findComment-802416 Share on other sites More sharing options...
nuttycoder Posted April 6, 2009 Author Share Posted April 6, 2009 just numbers on each line here's the contents of the file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 Quote Link to comment https://forums.phpfreaks.com/topic/152798-solved-pagination-problem/#findComment-802436 Share on other sites More sharing options...
mrMarcus Posted April 6, 2009 Share Posted April 6, 2009 echo $from + ceil($totalResults / $totalPages) returns 18; there's your problem Quote Link to comment https://forums.phpfreaks.com/topic/152798-solved-pagination-problem/#findComment-802452 Share on other sites More sharing options...
nuttycoder Posted April 6, 2009 Author Share Posted April 6, 2009 Thanks do you know what I could use instead? Quote Link to comment https://forums.phpfreaks.com/topic/152798-solved-pagination-problem/#findComment-802469 Share on other sites More sharing options...
sasa Posted April 6, 2009 Share Posted April 6, 2009 $from + $limit Quote Link to comment https://forums.phpfreaks.com/topic/152798-solved-pagination-problem/#findComment-802501 Share on other sites More sharing options...
nuttycoder Posted April 6, 2009 Author Share Posted April 6, 2009 yeah thats done the job thanks very much. Quote Link to comment https://forums.phpfreaks.com/topic/152798-solved-pagination-problem/#findComment-802505 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.