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
kpraman
Forum Contributor
Posts: 172 Joined: Fri Oct 13, 2006 10:54 am
Post
by kpraman » Wed Apr 18, 2007 2:56 am
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?
aaronhall
DevNet Resident
Posts: 1040 Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:
Post
by aaronhall » Wed Apr 18, 2007 2:58 am
Hint: arrays have numbered keys
kpraman
Forum Contributor
Posts: 172 Joined: Fri Oct 13, 2006 10:54 am
Post
by kpraman » Wed Apr 18, 2007 3:49 am
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
aaronhall
DevNet Resident
Posts: 1040 Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:
Post
by aaronhall » Wed Apr 18, 2007 4:04 am
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 » Wed Apr 18, 2007 4:29 am
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 » Wed Apr 18, 2007 4:37 am
I think is because of these
Code: Select all
$limit_file=$limit + $start;
// you should use
$last_file=$limit_file + $limit;