blueman378 Posted March 11, 2008 Share Posted March 11, 2008 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 More sharing options...
cunoodle2 Posted March 11, 2008 Share Posted March 11, 2008 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 More sharing options...
blueman378 Posted March 11, 2008 Author Share Posted March 11, 2008 i was hoping we could jsut use my original code and modify it to load the $file into an array and pull them out alpabetically with a foreach statement Link to comment https://forums.phpfreaks.com/topic/95572-help-to-order-modules/#findComment-489273 Share on other sites More sharing options...
blueman378 Posted March 11, 2008 Author Share Posted March 11, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.