sandy1028 Posted August 24, 2007 Share Posted August 24, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/66477-column-pagination/ Share on other sites More sharing options...
sandy1028 Posted August 24, 2007 Author Share Posted August 24, 2007 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].' '; } } Quote Link to comment https://forums.phpfreaks.com/topic/66477-column-pagination/#findComment-332855 Share on other sites More sharing options...
xyn Posted August 24, 2007 Share Posted August 24, 2007 whats the problem Quote Link to comment https://forums.phpfreaks.com/topic/66477-column-pagination/#findComment-332858 Share on other sites More sharing options...
sandy1028 Posted August 24, 2007 Author Share Posted August 24, 2007 the data of all column is displayed in page 1 and rest of the pages is blank I have divided the columns of 5. Quote Link to comment https://forums.phpfreaks.com/topic/66477-column-pagination/#findComment-332866 Share on other sites More sharing options...
xyn Posted August 24, 2007 Share Posted August 24, 2007 i'm a little confused really. Quote Link to comment https://forums.phpfreaks.com/topic/66477-column-pagination/#findComment-332868 Share on other sites More sharing options...
xyn Posted August 24, 2007 Share Posted August 24, 2007 http://www.phpfreaks.com/tutorials/43/0.php Quote Link to comment https://forums.phpfreaks.com/topic/66477-column-pagination/#findComment-332871 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.