pagination

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
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

pagination

Post by kpraman »

I am using the below code to display contents of directory.

Code: Select all

$dir = "on_line_course/";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
		    if($file !='.' && $file !='..')
			{
            	echo "filename: $file : filetype: " . filetype($dir . $file);
				echo "<br>";
			}
        }
        closedir($dh);
    }
}

I want to make paging without the use of database, is it possible to do?
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Hint: arrays have numbered keys
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

Post by kpraman »

Thanks for replying.

This is the code i tried,

Code: Select all

$count=count($filename);

$num = $_GET['num'];
if(empty($num)){
$num = 1;
};
$limit = 6;

$start = ($num-1)*$limit;
$start = round($start,0);


//$limit=$limit + $start;

$limit_file=$limit=$limit + $start;
echo "start $start";
echo "<br/>";
echo "limit $limit";
echo "<br/>";

for($i=$start;$i<=$limit;$i++)
{
   echo $filename[$i];
   echo "<br/>";
}

$totalpages = ceil($count / $limit);
$totalpages = round($totalpages,0);

echo $totalpages;

$c = 0;
echo "<br>";
while($c<$totalpages){
$page = $c + 1;
if($_GET['num']==$page){
echo "[$page] ";
}else{
echo "<a href=?num=$page class='pagenum'>[$page] </a>";
}
$c = $c+1;
}
The links are giving problems
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

All HTML element parameters must be enclosed in double quotes

Code: Select all

echo "<a href=\"?num=$page\" class=\"pagenum\">[$page] </a>";
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

Post by kpraman »

the links are displaying correctly. When i click on the links the links shows wrong numbers.
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Post by Rovas »

I think is because of these

Code: Select all

$limit_file=$limit + $start; 
// you should use
$last_file=$limit_file + $limit;
Post Reply