Dustin013 Posted July 12, 2008 Share Posted July 12, 2008 I have a script that scans a media directory looking for a particular structure. root directory to start scan c:\mediadirectory scans all top level directories and saves information to 'shows' table c:\mediadirectory\showname scans all sub directories, like part 1, part 2, part 3 and places that information into a 'part' table c:\mediadirectory\showname\part1\ then last it scans the actual media files within the part directories and places this information into a 'mediafile' table. c:\mediadirectory\showname\part1\mediafile1.mp4 Now I have to have 3 php scripts to allow a user to find the media file, each simply querying the database. On page.php the user has the option of selecting A-Z and #. This simple tells page2.php what to query. On page2.php the variable "page2.php?$item=A" would be passed through the URL thus resulting in a query that echos all directories that start with A. Now, page3.php gets the variable $directory=foldername&part=1 for instance. This queries the database looking for all parts directories within the show directory and then will display all the media files for the chosen folder. So again, from first page I click "A". The second page loads up all listings with the letter A. I click the Apple link that is displayed and I am directed to a third page which displays all the subfolders within the directory "Apple". I click Part1 and I am directed to a page displaying the names of all the media files within the Part1 folder. From there I can download or whatever. This process is dead simple, yet I don't like how users have to go through 3-4 different "pages" (3-4 clicks is fine, but I would like to keep it on the same page) simply to get to an item. I am working with the EXTJS framework and I am still new to it but I am using autoLoad:'page.php' inside of a region. So if I could get the above to function in as a single seamless page using PHP that would save me a lot of headache. Any suggestions? Here is the query example code below... I omitted the A-Z page simply because its not needed.... just remember its passing $item through the URL (page2.php?item=D) page.php <?php include 'include/config.php'; include 'include/connect.php'; $item = $_GET['item']; $query = "SELECT * FROM `shows` WHERE `showname` LIKE CONVERT( _utf8 '".$item."%' USING latin1 ) COLLATE latin1_swedish_ci"; $result = @ mysql_query ($query) or die ("Query '$query' failed with error message: \"" . mysql_error () . '"'); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<a href='page2.php?item={$row['showname']}'><tr>{$row['showname']}</a></tr> "; } ?> page2.php <?php include 'include/config.php'; include 'include/connect.php'; $item = $_GET['item']; $query = "SELECT * FROM `seasons` WHERE `showid` LIKE CONVERT( _utf8 '".$item."' USING latin1 ) COLLATE latin1_swedish_ci"; $result = @ mysql_query ($query) or die ("Query '$query' failed with error message: \"" . mysql_error () . '"'); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<a href='page3.php?item=".$item."&season={$row['seasonid']}'><tr>{$row['seasonid']}</tr></a> "; } ?> page3.php <?php include 'include/config.php'; include 'include/connect.php'; $item = $_GET['item']; $season = $_GET['season']; ?> <?php $query = "SELECT * FROM `episodes` WHERE `showid` LIKE CONVERT( _utf8 '".$item."' USING latin1 ) COLLATE latin1_swedish_ci AND `seasonid` LIKE CONVERT( _utf8 '".$season."' USING latin1 ) COLLATE latin1_swedish_ci"; $result = @ mysql_query ($query) or die ("Query '$query' failed with error message: \"" . mysql_error () . '"'); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<a href='({$row['path']}/{$row['mediatitle']})'><tr>{$row['mediatitle']}</tr></a> "; } ?> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 12, 2008 Share Posted July 12, 2008 Sounds like you need to look into AJAX. It will allow you to load content from the database and display it on the screen without reloading the whole page. There's an FAQ here that will show you the general idea, though it is done without a database. Perhaps starting with a search for AJAX tutorials would be best. Quote Link to comment Share on other sites More sharing options...
Dustin013 Posted July 12, 2008 Author Share Posted July 12, 2008 Thanks mate, that post is helpful. I was trying to avoid the whole AJAX solution but it doesn't seem too difficult. I will play around with it :-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.