Page 1 of 1

Make script dispaly page numbers dependant on results

Posted: Mon Nov 29, 2004 7:19 am
by Abz
hello,

iv already posted a problem afew posts away, and iv got that issue resolved, am wondering how could i make this script display the other fileds on another page,

Code: Select all

<?PhP
#THIS IS THE CODE, DON'T MESS!

$handle=opendir(".");
while (($file = readdir($handle))!=false){
rtrim($file);
if($file=="*.*"){
$file=readdir($handle);
$file=readdir($handle);
}
if($file=="hits.txt"){
$file=readdir($handle);
}
if(eregi("[a-zA-Z0-p_-]*.txt",$file)!=false){
$spliter=explode(".",$file);
$filea="$spliter[0].avi";
$filei="TEXT INFO";
$filez="$spliter[0].avi";
$size=filesize($filez);
$size=($size/1024);
$size=round($size,1);
$info="  Text info files have not yet been created..";
echo "<TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=0 CLASS=TABLEMAIN><TR>";
echo "<TD CLASS=TDTOP colspan=1><IMG SRC="3dsmax/mov/blank.gif" width=1 height=20></TD>";
echo "<TD CLASS=TDFILESIZE WIDTH=30%></TD></TR>";
echo "<TR><TD CLASS=TDTITLECONTENT>";
echo "<img src="hiddin/box.gif"><IMG SRC="3dsmax/mov/blank.gif" width=5 height=1><A HREF="" onClick="window.open('$filea','cal','width=600,height=400,status=no,scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no');return false">$spliter[0]</A></B></TD><TD CLASS=TDFILESIZE>Size: $size Kb";
echo "</TD></TR>";
echo "<TR><TD colspan=2 width=100% CLASS=TDCONTENT>";
$filer="$file";
$file=file($filer);
$sline=0;
$count=count($file);
$eline=$count;
$i = $count;
for($j=$sline;$j<$eline;$j++){
echo "$file[$j]";
}
echo "</TD></TR>";
echo "<TR CLASS=TDBOT>";
echo "<TD CLASS=TDBOT>";
echo "<IMG SRC="3dsmax/mov/blank.gif" width=1 height=20>";
echo "<TD CLASS=TDDOWNLOAD><A HREF="" onClick="window.open('$filea','cal','width=600,height=400,status=no,scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no');return false">[] PLAY</A></TD>"; 
echo "</TD></TR></TABLE>";

} else {

}

}
?>
the script as you might or might not know, displays the content of a directory, if i have a large amout of files in that directory then am sure you relise how big the page would become,

so like after the script displays 10 fields it gives it displays a total of pages and current page, etc...

Thanks again for all the support, I am very grateful :),

Abs

Posted: Mon Nov 29, 2004 7:48 am
by Maugrim_The_Reaper
I assume you can do some creative jockeying within the FOR loop.

Essentially $j carries the current file number. So when $j >= 10 (see below for a auto check), add a section with number of files total ($eline?), plus page links for each 10 files thereafter.

The links would have to carry new value for $sline so that the loop is once again reconstituted to skip the previous files, and move to the next ten.

You'd have to modify $sline to check whether its value is being passed by GET (i.e. url) and set them to the URL values if they exist.

Code: Select all

<?php

for($j=$sline;$j<$eline;$j++){
    $res_check = $j - $sline; //$j will increment until it = $sline+10
    echo "$file[$j]";
    // check if 10th file displayed
    if($res_check >= 10){
        //add page nav links here
        break 1;
    }
}

?>
The links should pass values for $sline - i.e. which file number the list should start with (the starting value of $j)
So $sline will need to be set similar to:

Code: Select all

<?php
if(!empty($_GET['sline']) && is_number($_GET['sline'])){
    $sline = $_GET['sline'];
}
else
{
    $sline = 0;
}

?>
Creating the links should be as simple as creating links with $sline set to increments of 10, i.e. sline=0, sline=10, sline=20, etc. within each url. You can assign a page number to each in the href text.

There may be a simpler way of doing this - no doubt the resident experts will have some wisdom to offer :)

?>