Jump to content

column Pagination


sandy1028

Recommended Posts

Hi,

 

I have a problem in pagination of columns. 5 columns should be displayed in a page. Help me in displaying the rows based on columns.

All the columns are displayed in first page. Help me with this

 

 

<?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);

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

 

data.txt



 

 

 

Link to comment
Share on other sites

Hi,

 

I have a problem in for loop please help me

$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);
$rows=count($tex);

for($i=0;$i<=$rows;$i++){

for($j = 0; $j<=5 ; $j++) {
$output.=$tex[$i][$j].' ';
}
}



Link to comment
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.