|
Posted by Faux_Pseudo on 09/25/91 11:34
_.-In alt.php, juglesh wrote the following -._
> Make an array of the items in the dir using readdir, etc.
> Loop thru the array, checking each entry against the current page
> when you know that current page is $list[$i], you know that the next
> page is $list[$i+1]
<snip code>
Thank you very much. I have little (ie less than two days worth) of
experiance with PHP. Your example code was /just/ enough to help me
get a working solution. I hunted out your bugs and filled in the
missing functions.
One glairing thing I don't likeis my way of finding the page name I am
in:
// Set this page as which will be hard coded into page by
// pre-processing script unless someone knows of a better way to get
// the name of the file they are in
$ThisPage = "mmmm.html";
I left my debugging notes in but commented.
<?
// create an array with all the valid filenames
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != ".index" && $file != "index.html") {
$List[] = $file;
}
}
closedir($handle); };
// asciibettical the array
sort($List);
// print_r($List);
// count the array
$NumberOfFiles = count($List);
// echo "$NumberOfFiles\n";
// Set this page as which will be hard coded into page by
// pre-processing script unless someone knows of a better way to get
// the name of the file they are in
//$ThisPage = "aaaa.html";
//$ThisPage = "zzzz.html";
$ThisPage = "mmmm.html";
// echo "This page is = \"$ThisPage\"\n";
// find the place in the indext for $ThisPage
for($i=0; $i<$NumberOfFiles; $i++) {
$now = $List[$i];
if($now == $ThisPage) { $ThisIndex = $i; }
}
// echo "This page is = \"$ThisIndex\"\n";
// $ThisIndex is now the [index] of $List for the current page
// make sure dont go below 0 or over $NumberOfFiles
$mylinkprev = $ThisIndex - 1;
$mylinknext = $ThisIndex + 1;
$Previous = $List[$mylinkprev]; $Next = $List[$mylinknext];
// echo "test: \"$Previous\" | \"$Next\"\n";
if ($mylinkprev < 0)
// user went all the way back past the first file, show the last:
{
echo "<a href=\"$Previous\">Previous</a> | <a href=\"index.html\">Index</a>\n" ;
}
elseif($mylinknext > $NumberOfFiles - 1)
// user went clicked past the last file, show the first:
{
echo "<a href=\"index.html\">Index</a> | <a href=\"$Next\"></a>Next\n" ;
}
else
{
echo "<a href=\"$Previous\">Previous</a> | <a href=\"$Next\">Next</a>\n" ;
}
?>
> that's the idea, HTH!
Best programming lesson I have ever had.
--
.-')) fauxascii.com ('-. | It's a damn poor mind that
' ..- .:" ) ( ":. -.. ' | can only think of one way to
((,,_;'.;' UIN=66618055 ';. ';_,,)) | spell a word.
((_.YIM=Faux_Pseudo :._)) | - Andrew Jackson
[Back to original message]
|