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
https://forums.phpfreaks.com/topic/95572-help-to-order-modules/
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
https://forums.phpfreaks.com/topic/95572-help-to-order-modules/#findComment-489264
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
https://forums.phpfreaks.com/topic/95572-help-to-order-modules/#findComment-489288
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.