|
Posted by juglesh on 10/13/45 11:34
Faux_Pseudo wrote:
> Problem:
> How would one go about creating a dynamic listing so that the source
> of all pages in the dir don't need to be edited (by hand or by script)
> and will dynamically figure out what Back and Next would be if we were
> to add a file to this sample list.
>
> alian
> alison.art
> [...]
> windows
> wine
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]
$List = YourFunctionToRetrieveTheDirList('dir'); // array()
$numberOfFiles = count($List);
$thisPage = $_GET['page']; // or however you're doing it
//for all the pages in the folder
for($i=0; $i<$numberOfFiles; $i++)
{
$now = $List[$i];
if($now== $thisPage)
{
$thisindex = $i;
//echo "now=".$now;
}
}//-end that for
// $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;
if ($mylinkprev < 0)
// user went all the way back past the first file, show the last:
{
$mylinkprev = $numberOfFiles - 1;
}
if($mylinknext > $numberOfFiles - 1)
// user went clicked past the last file, show the first:
{
$mylinknext = 0;
}
$Previous = $List[$mylinkprev];
$Next = $List[$mylinknext];
--simplified from a script I made, you'll have to tinker with it, but
that's the idea, HTH!
--
juglesh
[Back to original message]
|