|
LITTLEBLACKDOG.COM
|
| Author |
Message |
guyguy50
Cat Chaser


Joined: 28 Apr 2001 Posts: 601
Location: Ludington
|
Posted:
Fri Jan 15, 2010 8:03 am Post subject: PHP simple question |
|
Revision because I explained that poorly... through a few functions I have gotten the results below:
Now what I am trying to do is figure out now is how do I get this into an ordered list using php. I have this list in a multidimesional array with the first group as array[0][0] ... array[0][1] ... array[0][2]... and so on and so forth. Now as you can see there are associated keys I'd like to pull to use. I've gone through a few loops of code and think that now I have done this all wrong any ideas to make that list work? All the information is read in dynamically from calls. The DNE is just a null marker to fill in the field to make them all the same size as the longest list... just happens it is 3 tiers for this example... but that is determined dynamically and have that issue solved... just now I have my sorted data... but stuck on how to move on from this part to get it finally sorted for display purposes.
Quote:Newsletter
DNE
DNE
=====
Managament Documents
Shipping & Recieving
Shipping
=====
Managament Documents
Shipping & Recieving
Recieving
=====
Managament Documents
Random
pp
=====
Managament Documents
Random
ff
=====
Managament Documents
Random
dd
=====
Managament Documents
Pedestal
DNE
=====
Managament Documents
Lateral
DNE
=====
Managament Documents
Engineering
DNE
=====
Home
DNE
DNE
=====
Help
DNE
DNE
=====
Events
DNE
DNE
|
_________________
Quote:I am the Great Gibby bow before me!
Quote:R.I.P. Super Snoopy (October 10, 1995 - November 1, 2008)
|
|
|
|
|
guyguy50
Cat Chaser


Joined: 28 Apr 2001 Posts: 601
Location: Ludington
|
Posted:
Fri Mar 12, 2010 5:30 am Post subject: |
|
In case anyone cared, solved this months ago with this function. May be useful to someone, actually a group of functions used for various things.
First part makes an array for ranking, then second one just simply displays using newer iteration techniques, had to use opendir for what I wanted to get the ranking and with use of a stopper file too. But it works wonderful and remarkably faster then I expected.
<?php
function Load_Tree($path, $stopper)
{
$delim = "/";
if ($dir=@opendir($path)) {
while (($element=readdir($dir))!== false)
{
if (is_dir($path.$delim.$element) && $element!= "." && $element!= ".." && $element!="Search")
{
$array[$element] = Load_Tree($path.$delim.$element, $stopper);
}
elseif ($element!= "." && $element!= "..")
{
$element = strtolower($element);
if($element == $stopper)
{
$array = array(); //DESTROY THE ARRAY IF THERE IS EVER A STRUCT FILE IN THE DIRECTORY
$array[0] = "LINK_ME";
break;
}
}
}
closedir($dir);
}
return (isset($array) ? $array : false);
}
function Nav_Link($value_array, $key_sub)
{
foreach ($value_array as $key => $value)
{
if (is_array($value) == FALSE)
{
//We do nothing Here all is taken care of in recursive section
}
if (is_array($value) == TRUE)
{
if($value[0] == "LINK_ME")
{
$temp_key = $key_sub.'/'.$key;
$temp_key = urlencode($temp_key);
echo ('<li><a href="index.php?page='.$temp_key.'">'.$key.'</a></li>');
}
else
{
echo ('<li><a href="#">'.$key.'</a>
<ul>');
Nav_Link($value, $key_sub.'/'.$key);
echo (' </ul>
</li>');
}
}
}
}
function Tree_Noder($tree_path, $orig_path)
{
$I_T_H = NULL; // I_T_H used to detect of there is anything to list. Else main program displays something like a message or the like.
$iterator = new DirectoryIterator($tree_path);
foreach ($iterator as $fileinfo)
{
if ($fileinfo->isFile() && $fileinfo!= 'struct.php' && $fileinfo!='index.php'&& $fileinfo!='index.htm'&& $fileinfo!='index.html'&& $fileinfo!='Thumbs.db')
{
$file = $fileinfo->getFilename(); //prints file
$path = $fileinfo->getPath(); // get path
//echo $file."<br>";
$file_array = explode("_",$file);
$form_num = $file_array[0];
$form_name = $file_array[1];
if($form_name != "")
{
//$file_array = explode(".",$form_name); // WAS USED TO REMOVE SUFFIX BUT NAMES HAVE "." in them too
//$form_name = $file_array[0];
echo ('<li><span class="file"><b>Name</b><strong> : </strong><a class="five" href="'.$path.'/'.$file.'" target="_blank">'.$form_name.'</a> <br><b>Form Number</b><strong> : </strong><a class="four" href="'.$path.'/'.$file.'" target="_blank">'.$form_num.'</a></span></li>');
}
else
{
//$file_array = explode(".",$file); // WAS USED TO REMOVE SUFFIX BUT NAMES HAVE "." in them too
//$form_name = $file_array[0];
echo ('<li><span class="file"><a class="four" href="'.$path.'/'.$file.'" target="_blank">'.$file.'</a></span></li>');
}
//<li><span class="file"><a href="#">Airdrie eNewsletters</a></span></li>
$I_T_H = 1;
}
//echo $orig_path;
if($fileinfo->isDir()&&$fileinfo != $orig_path)
{
if($fileinfo->isDot()) continue; //bypasses . & ..
$folder = $fileinfo->getFilename(); //prints directory//
if($folder == "Obsolete") continue; //bypasses Obsolete folders
if($folder == "THUMBS") continue; //bypasses THUMBS for now
//echo "D->".$folder."<br>";
echo('<li><span class="folder"><strong>'.$folder.'</strong></span>
<ul>');
//<li><span class="folder"><strong>Home</strong></span>
//<ul>
Tree_Noder($tree_path.'/'.$folder,$orig_path);
echo "</ul>";
$I_T_H = 1;
}
}// end of foreach
return $I_T_H;
}
?>
<?php
|
_________________
Quote:I am the Great Gibby bow before me!
Quote:R.I.P. Super Snoopy (October 10, 1995 - November 1, 2008)
|
|
|
|
|
|
|
|
|
View next topic
View previous topic
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB
© 2001, 2002 phpBB Group
phpBB SEO
All times are GMT - 8 Hours
Help us keep advertisements off this site. Donate today!
|
|