Page 1 of 1

PHP searching...folders and subfolders..

Posted: Mon Jul 09, 2007 11:03 pm
by slonison
Ok I'm here to ask not how-to but how-would-you.. I'm not really interested in recieving actual code but rather the path you'd take in implementing what I'm trying to do.

I'm trying to make a search engine on my website that will search a mysql database.

Now I already have the database completed. It contains the headers {Name}{Ext}{Path}{Date}{Size}
As you can guess it's a file search engine. The problem I'm having is with displaying the information.

I want to make the results display in the format of a collapsible list.

Code: Select all

//servername/Movies/100 Girls/100 Girls (fullscreen) (DVD Rip - DivX).avi : 724. MB
//servername/Movies/100 Girls/Thumbs.db : 0.00 MB
//servername/Movies/40 year old virgin/dmd-40yearoldv-cd1.avi : 731. MB
//servername/Movies/40 year old virgin/dmd-40yearoldv-cd2.avi : 731. MB
//servername/Movies/American History X.avi : 953. MB
//servername/Movies/American Pie - Band Camp/American Pie Band Camp (2005) (V).avi : 734. MB
//servername/Movies/American Pie 1/American Pie [DivX].avi : 702. MB
//servername/Movies/American Pie 1/Thumbs.db : 0.00 MB
For example,
If the user searched for pie.
I would like the results to just show the word Movies. Then if you clicked on movies, two options would show, American Pie 1 and American Pie - Band Camp. Both of which would be their own collapsible lists containing the files within each subdirectory respectively.

I was originally thinking along the lines of creating a huge mysql table with enough subdirectory cells to hold files within 10 subdirectories but it became messy, so I was think that perhaps there may be some way to do it with just the entire file path and the explode() function. What do you guys think?

Posted: Mon Jul 09, 2007 11:12 pm
by feyd
explode() is the route to take. Likely, I would recombine the resulting arrays into a single array of elements creating a tree of arrays, then simply iterate the entire list.

Posted: Tue Jul 10, 2007 11:59 am
by slonison
Sorry I did say I didnt want code, but I'm having a little trouble doing this...

Posted: Tue Jul 10, 2007 12:29 pm
by vigge89
What have you got/done so far?

Posted: Tue Jul 10, 2007 1:02 pm
by slonison

Code: Select all

<?php

function displayResults()
{
   $keyword="comedy";
   $con = mysql_connect("localhost","username","password");
   if (!$con)
   {  
       die('Could Not Connect: ' . mysql_error());
   }

   mysql_select_db("bbb",$con);

   $result = mysql_query("SELECT * FROM server2 WHERE (Name LIKE '%$keyword%') OR (Path LIKE '%$keyword%') ORDER BY Path ASC, Name ASC");



   echo '<ul>';

   while($row = mysql_fetch_array($result))
   {
       $ex_row = explode("/",$row['Path']);
       $ex_row1 = explode("/",$row1['Path']);

       if($ex_row1[5] != $ex_row[5])
       {
           echo '</ul></ul><ul>' . $ex_row[5];
           echo '<ul><li>' . $row['Name'] . '</li>';
       }
       else
       {
           echo '<li>' . $row['Name'] . '</li>';
       }

       $row1 = $row;
   }

}



?>

<?

displayResults();

?>
Displays like this:

Code: Select all

George Carlin - 40 Years in Comedy
          o 01 40 Years in Comedy.mp3

      George Carlin - Back in Town
          o Back In Town.Mp3

      George Carlin - You Are All Diseased [DivX][Comedy][1999][DVDRip]
          o George Carlin - You Are All Diseased [DivX][Comedy][1999][DVDRip].avi
          o Thumbs.db

      George Carlin Life is worth losing
          o George.Carlin.Life.Is.Worth.Losing.HBO.Special.HDTV.XviD-SAiNTS.avi
          o Thumbs.db

      George Carlin-Complaints and Grievances MentalRG
          o VTS_01_1.avi

      Lewis Black - Black On Broadway
          o Lewis Black - Black On Broadway.mpg
          o Thumbs.db

It's the collapsibleness that I'm gonna have a hard time with putting in the span tags I suppose...

Posted: Tue Jul 17, 2007 11:12 pm
by slonison
Ok I had to rewrite everything. The previous post code worked but only if everything was in that exact amount of folders.

Can [s]some1[/s] someone help me rewrite the code so that it works with any number of subdirectory folders. as in

Code: Select all

//servername/Movies/George/wow.avi
//servername/Movies/George/wow2.avi
//servername/Movies/George2/wow.avi
//servername/Movies/George3/wow.avi
//servername/Movies/George4/wow.avi
//servername/Games/George/wow.avi
//servername/Tv/George/wow.avi
//servername/Tv/wow.avi
If I searched wow it would come up like:

Code: Select all

Movies
      George
          o wow.avi
          o wow2.avi
      George2
          o wow.avi
      George3
          o wow.avi
      George4
          o wow.avi
Games
      George
          o wow.avi
Tv
      George
          o wow.avi
      wow.avi

I've brained and Brained and Brained stormed but i can't get it to work with an unknown number of directories...
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.