Columns pagination problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rash28
Forum Commoner
Posts: 38
Joined: Wed Aug 01, 2007 1:21 am

Columns pagination problem

Post by rash28 »

Hi,

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].'&nbsp;';
}
}
}
$output.='<br />';
}
// create previous link
if($page>1){
$output.='<a href="'.$_SERVER['PHP_SELF'].'?page='.($page-1).'">Previous</a>&nbsp;';
}
// create intermediate links
for($i=1;$i<=$numPages;$i++){
($i!=$page)?$output.='<a href="'.$_SERVER['PHP_SELF'].'?page='.$i.'">'.$i.'</a>&nbsp;':$output.=$i.'&nbsp;';
}
// create next link
if($page<$numPages){
$output.='&nbsp;<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
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Your post is confusing... Why do you switch back and forth between describing columns and rows?

Due to the fact that you are using a file (and fail to use any whitespace whatsoever), your code is hard to follow. Why don't you try a database?
Post Reply