Results 1 to 7 of 7

Thread: How to output part of feild using mysql and php

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Arrow How to output part of feild using mysql and php

    Hi all. i got a huge list of mp3 that they are in diffrent folders. I put all the songs infor in mysql database in a table called files. I want a query db that output foldernames for me .The folder name is part of feiled called filename in files table. The value of filename is like this stored in db :

    http://localhost/wimpy5recursive/mp3s/album1/song1.mp3
    http://localhost/wimpy5recursive/mp3s/album2/song4.mp3
    where the bold part is the foldername. i want to print folder name.Note:mp3s is the root folder for mp3s.The whole point is to list all folders name and link to page that holds songs inside those folders.

    Furthermore, i want a query all feilds info for songs in each given folder.What i mean is that for each folder it lists all songs info iside that folder.I want to be able to tell the query what folder i want to list its song.Thanks

  2. #2
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: How to output part of feild using mysql and php

    we arent gunna do it for you.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  3. #3
    Member AWC_Joe's Avatar
    Join Date
    Jan 2006
    Location
    Located
    Posts
    49

    Re: How to output part of feild using mysql and php

    Not sure what your looking for... heres somthing i used to display mp3s from a Dir i would pass via url.com?folder=foldername

    PHP Code:
    if ($handle opendir($_GET['folder'])) {
        while (
    false !== ($file readdir($handle))) {
            if (
    $file != "." && $file != "..") {
                if (
    preg_match('#^(.+).mp3$#'$file$match)){
                        
    $files[] = $file;
                    } else {
                        
    $dirs[] = $file;
                    }
            }
        }
        
        
    closedir($handle);
        
        if (
    count($dirs) != 0) {
            
    sort($dirs);
            
    //echo "".$dirs[];
        
    }
        if (
    count($files) != 0) {
            
    sort($files);
        }
    }

    echo 
    "Sub Folders<hr align='left' width='74%'>" ;
    for (
    $i 0$i count($dirs); $i++) {
        echo 
    "<a href='?folder=".$_GET['folder']."/".$dirs[$i]."'>".$dirs[$i]."</a><br />" ;
    }

    echo 
    "<h2><hr align='left' width='52%'>".$_GET['folder']." (".count($files).")<hr align='left' width='52%'></h2>";

    for (
    $i 0$i count($files); $i++) {
        
    $date date("M j Y",filectime($_GET['folder']."/".$files[$i])) ;
        
    $size formatsize(filesize($_GET['folder']."/".$files[$i])) ;
        echo 
    $date." &nbsp; <a href='".$_GET['folder']."/".$files[$i]."'>".$files[$i]."</a> - ".$size."<br />" ;

    |
    Some programs and scripts ive made: http://wiki.anotherwebcom.com
    What was once an opinion, became a fact, to be later proven wrong...

  4. #4
    Member juanmf's Avatar
    Join Date
    Dec 2005
    Location
    Mordor
    Posts
    46

    Thumbs down Re: How to output part of feild using mysql and php

    AGREE WITH PlaGuE!
    NEXT TIME U HAVE A PROBLEM LIKE THIS U´LL LOSE LESS TIME THINKING.
    IT CAN BE MADE BY THE MYSQL SERVER WHITH FUNCTIONS OR DOIT YOUR SELF IN CODE.
    Last edited by juanmf; Mar 4th, 2006 at 05:10 PM.
    If an answer to your question has been helpful, then please, Rate it! where are u?
    On Staying Informed and Intellectual Self-Defense

    There's no way to be informed without devoting effort to the task, whether we have in mind what's happening in the world, or anything else. Understanding doesn't come free. But it's feasible for anyone who is part of a cooperative community -- Same holds for "intellectual self-defense."

    By Noam Chomsky

  5. #5
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: How to output part of feild using mysql and php

    Quote Originally Posted by AWC_Joe
    Not sure what your looking for... heres somthing i used to display mp3s from a Dir i would pass via url.com?folder=foldername

    PHP Code:
    if ($handle opendir($_GET['folder'])) {
        while (
    false !== ($file readdir($handle))) {
            if (
    $file != "." && $file != "..") {
                if (
    preg_match('#^(.+).mp3$#'$file$match)){
                        
    $files[] = $file;
                    } else {
                        
    $dirs[] = $file;
                    }
            }
        }
        
        
    closedir($handle);
        
        if (
    count($dirs) != 0) {
            
    sort($dirs);
            
    //echo "".$dirs[];
        
    }
        if (
    count($files) != 0) {
            
    sort($files);
        }
    }

    echo 
    "Sub Folders<hr align='left' width='74%'>" ;
    for (
    $i 0$i count($dirs); $i++) {
        echo 
    "<a href='?folder=".$_GET['folder']."/".$dirs[$i]."'>".$dirs[$i]."</a><br />" ;
    }

    echo 
    "<h2><hr align='left' width='52%'>".$_GET['folder']." (".count($files).")<hr align='left' width='52%'></h2>";

    for (
    $i 0$i count($files); $i++) {
        
    $date date("M j Y",filectime($_GET['folder']."/".$files[$i])) ;
        
    $size formatsize(filesize($_GET['folder']."/".$files[$i])) ;
        echo 
    $date." &nbsp; <a href='".$_GET['folder']."/".$files[$i]."'>".$files[$i]."</a> - ".$size."<br />" ;

    That is not a very safe peice of code to use as you could supply the path to any directoy on the server in the URL.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  6. #6
    Member AWC_Joe's Avatar
    Join Date
    Jan 2006
    Location
    Located
    Posts
    49

    Re: How to output part of feild using mysql and php

    Quote Originally Posted by visualAd
    That is not a very safe peice of code to use as you could supply the path to any directoy on the server in the URL.
    That crossed my mind, but the idea was to list off all mp3s in the dirs with cleaner details then just opening up the dirs for browsing. By limiting what files can be displayed with preg_match, would you still say its unsafe (with the intent i stated) ?

    Thanks for your input.

    _
    |
    Some programs and scripts ive made: http://wiki.anotherwebcom.com
    What was once an opinion, became a fact, to be later proven wrong...

  7. #7
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: How to output part of feild using mysql and php

    I guess that depends upon whether you mind people searching for mp3 files elsewhere on your server.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width