Link to home
Start Free TrialLog in
Avatar of browolf
browolf

asked on

getting mixed up with folders

Hi,

I've got a directory

/scams/examples

which contains atm 5 subdirectories. each of the these subdirectories contains some images.
i'm trying to make an <ul> in the form
<ul>
<li>foldername</li>
          <ul>
           <li>image url</lil>
           <li>etc</li>
          </ul>
<li> etc </li>
</ul>

i wrote some php which vaguely worked but only looped once. have been moving bits around but now it works even less. i think i've gotten a bit mixed up with so many sub loops. can someone have a look please.

<ul>
<?
$path = "scams/examples";
$dir_handle = @opendir($path) or die("Unable to open $path");
chdir($path);
while (false !== ($file = readdir($dir_handle))) {
       //check for scam folder names
       if (is_dir($file) && $file != "." && $file != "..") {
           //echo ("hello?<br>");
           echo ("<li>$file</li>\n");
           $path2 = ("$file");
           $dir_handle2 = @opendir($path2) or die("Unable to open $path2");
           chdir($path2);
           while (false !== ($file2 = readdir($dir_handle2))) {
                  echo ("  <ul>\n");
                  //check for scam images in folder $file
                  if (!is_dir($file2) && $file2 != "." && $file2 != "..") {
                          $query="SELECT id,subject FROM examples WHERE filename='$file2'";
                            $result=@mysql_query($query);
                          if ($result){
                                                   while ($row = mysql_fetch_array($result,MYSQL_NUM)) {
                                        //echo ("$file2");
                                        $page="scams/phishing.php?id=$row[0]";
                                        echo ("&nbsp;&nbsp;<li><a href=\"$root$page\">$row[1]</a></li>\n");
                                        mysql_free_result($result);
                                     }
                           }
                    }
           closedir($dir_handle2);
           echo ("</ul>\n");
       }

}
       chdir($path);


}
closedir($dir_handle);

?>

</ul>


the source comes out as

<ul>
<li>HSBC</li>
  <ul>
</ul>

</ul>

at one point i had it making the creating the a href for the hsbc image but now it doesnt. (there's was only one image in the hsbc folder.

thanks for any assistance.

ASKER CERTIFIED SOLUTION
Avatar of a2liter
a2liter

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of browolf
browolf

ASKER

thanks a lot thats ace. I don't think i'd have ever thought of doing it like that. I'm newish to php,
all i had to change is this

$newpath = "$base/$dir";

cos  my site is hosted on a linux/unix based system. I dont need any error checking cos there wont ever be empty folders. i'll only create folders when i have something to put in them. there'll be a slight window i suppose.

the page in question is at:  http://www.antiphishing.org.uk/scams.php


regards