I have a pagination code and also txt file.
I have used pagination for the column wise. The all the column data is printed on first page, second and third page is empty.
How to display all the rows based on the columns. i.e 10 columns in each page
Code: Select all
<?php
$file='data.txt';
function paginateRecords($file,$page,$numRecs=10){
$data=array_reverse(file($file));
// calculate total of records
foreach($data as $line){
$text_line=explode("|",$line);
foreach($text_line as $text){
$tex=explode(":",$text);
$numPages=ceil(count($text_line)/$numRecs);
}
}
// validate page pointer
if(!preg_match("/^\d{1,2}$/",$page)||$page<1||$page>$numPages){
$page=1;
}
// retrieve records from flat file
$data=array_slice($data,($page-1)*$numRecs,$numRecs);
// append records to output
foreach($data as $line){
$text_line=explode("|",$line);
foreach($text_line as $text){
$tex=explode(":",$text);
for($i=0;$i<=5;$i++){
for($j=$i; $j<count($data[$i]);$j++){
$output.=$tex[$i][$j].' ';
}
}
}
$output.='<br />';
}
// create previous link
if($page>1){
$output.='<a href="'.$_SERVER['PHP_SELF'].'?page='.($page-1).'">Previous</a> ';
}
// create intermediate links
for($i=1;$i<=$numPages;$i++){
($i!=$page)?$output.='<a href="'.$_SERVER['PHP_SELF'].'?page='.$i.'">'.$i.'</a> ':$output.=$i.' ';
}
// create next link
if($page<$numPages){
$output.=' <a href="'.$_SERVER['PHP_SELF'].'?page='.($page+1).'">Next</a> ';
}
return $output;
}
//require_once('pager.php');
$page=$_GET['page'];
echo paginateRecords($file,$page);Code: Select all
User1 : 23 : 23 :45 | user2 : 32 : 33 : 34 | User3 : 23 : 33 : 455 |User4 : 34 : 9: 34 |User5 : 023 : 233: 435 |User6 : 2 : 3: 5 |User7 : 33 : 33: 434 |User8 : 323 : 3: 4 |User9 : 33 : 53: 445 |User10 : 23 : 23 :45 |User11 : 23 : 23: 45 |User12 : 23 : 23 :45 |User13 : 23 : 23 : 45 |User14 : 23 : 23 : 45 |User15 : 23 : 23 : 45 |User16 : 23 : 23 : 45 |User17 : 23 : 23 : 45 |User18 : 23 : 23 : 45 |User19 : 23 : 23 : 45 |User20 : 23 : 23 : 45 |User21 : 23 : 23 : 45 |User22 : 23 : 23 : 45 |User23 : 23 : 23 : 45 |User24 : 23 : 23 : 45| : 34 :5 : 34