Jump to content

help to order "modules"


blueman378

Recommended Posts

hi guys well heres my code

$modulepath = "{$root}moduleleft";
$sectionListIgnore = array ('.','..','template.php');
$dh = opendir($modulepath);
while (false !== ($file = readdir($dh))) 
{
if(!in_array($file,$sectionListIgnore)){
        include("{$root}moduleleft/{$file}");
    }
}
closedir($dh); 
}

but the thing is this code lists the files by the modified date,

oldest to newest

 

how would i make it so that they were ordered by $x?

Link to comment
Share on other sites

You say you want to sort by $x but never mention what that means.  I assume alphabetical order..

 

Shamelessly stole this from php manual on-line...

 

<?php
$i = 0;
$arraycount = 0;
$home="/home/cabal/public_html/b146/admin/$stats";

if ($stats)
{
    $dircheck="/home/cabal/public_html/b146/admin/$stats";
    if (is_dir($dircheck))
    {
        if ($handle = opendir($home))
        {
            while (false !== ($file = readdir($handle)))
            {
                   if ($file != "." && $file != "..")
            {
            $path = "$home/$file";
            $extension = array_pop(explode('.', basename($path)));
            $filearray[$i] = $file;
            $i++;
            }
            }
           }
           closedir($handle);
       
    }
    else
    {
    echo "INCORRECT SELECTION";
    }

}

else

{
echo "NOTHING SELECTED";
}
echo " ";

echo("<table width='100%' border='1'><tr><td><b><font color='#ff0000'>");
echo("$stats : Log File");
echo("</b></font></td><td><font color='#FF0000'><b>Page Views</b></font></td></tr>");
sort($filearray);
reset($filearray);
while (list($key, $val) = each($filearray))
{
    $includearray = "$home/$filearray[$key]";
    echo("<tr><td>");
    echo("$val");
    echo("</td><td>");
    include($includearray);
    echo("</td></tr>");
   
}
echo("</table>");

?>

 

Check it out for yourself here..

http://us2.php.net/opendir

Link to comment
Share on other sites

well i jsut combined the codes:

<?php
$i = 0;
$arraycount = 0;
$modulepath = "{$root}moduleright";
$sectionListIgnore = array ('.','..','template.php');
$handle = opendir($modulepath);
           
	while (false !== ($file = readdir($handle)))
            {
                   if ($file != "." && $file != "..")
            {
            $path = "$modulepath/$file";
            $extension = array_pop(explode('.', basename($path)));
            $filesarray[$i] = $file;
            $i++;
            }
            }
           closedir($handle);

sort($filesarray);
reset($filesarray);
while (list($key, $val) = each($filesarray))
{
    $includearray = "$modulepath/$filesarray[$key]";
    include($includearray);   
}
?>

cheers

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.