Results 1 to 11 of 11

Thread: Filter Table

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Filter Table

    Here is my php code:

    PHP Code:
    <?php
    echo '<h2>Existing Files on your account:</h2>';
    // Define the full path to the folder whose contents you want to list
        
    $path "uploads/";
        
    // Open the directory
        
    $dir_handle = @opendir($path) or die("Error opening $path");
        
    // Loop through the files
    echo '<div style="border: 2px solid rgb(0, 0, 0);">'
    echo 
    '<table border=1>';    
    while (
    $file readdir($dir_handle)) {
          if(
    $file == "." || $file == ".." || $file == "index.php" ) { continue; }
    if (
    substr($file,($file 3)) != "raf") {
    //List all mp3 files
    echo '<tr>';
    echo 
    '<td>';
    echo 
    $file;
    echo 
    '</td>';
    $raffile fopen(("uploads/" . (substr($file,0,($file 3)) . "raf")), "r") or exit("Unable to 

    open file!"
    );
    //Output a line of the file until the end is reached
    while(!feof($raffile))
      {
    $cline fgets($raffile);
      echo 
    '<td>';
      echo (
    substr($cline,(strpos($cline,"=") + 1)));
      echo 
    '</td>';
      }
    fclose($raffile);
    echo 
    '</tr>';
    //List all mp3 files
    }
        }
    echo 
    '</table>';
    echo 
    '</div>';
    echo 
    '<br />';
    echo 
    '<BUTTON onclick="window.close();">Close Window</BUTTON>';
        
    // Close
        
    closedir($dir_handle);
    ?>
    There is a folder called uploads, in this folder there are different mp3 files. For each mp3 file there is an raf file with the same name. My code creates a table starting with the name of the mp3 file and then lists every line in the assosciating raf file in a new column.

    In most of the lines of the file a = sign can be found. I wrote some code to display only the text following the = sign.

    There are multiple lines in each raf file that that do not have = signs instead they start with [.

    Here is an example of an RAF file:

    Code:
    [raf]
    audioupdate=03/03/00-12:45:40
    audiotype=1
    
    [ann]
    user=false
    confirmplay=
    manualplay=true
    
    [alc]
    level=-3dB
    
    [autoplay]
    mins=0
    sequence=true
    
    [scheduling]
    commence=
    expire=
    timestart=00:00:00
    timeend=24:00:00
    daysofweek=127
    I do not want to list the [raf]/[ann]/[alc]/[autoplay]/[scheduling]. At the moment the table is listing all these lines but instead of, for example, [raf] it is being listed as raf]. Without the opening [.

    How do i filter out these lines starting with [?

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Filter Table

    this is an ini file. use parse_ini_file().

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: Filter Table

    Where would i place this function?

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Filter Table

    did you go to the link I gave you? parse_ini_file() parses the entire file and puts all of the information into an array. that means you would get rid of all of your fopen() and fread() calls and just loop through the array created to display the information. you can either parse the file with or without sections, and both are shown in examples.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: Filter Table

    Thank you, also my file is a .raf file. Would it still be read as a .ini using this function?

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Filter Table

    yes.

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

    Re: Filter Table

    Quote Originally Posted by noahssite View Post
    Here is my php code:

    PHP Code:
    <?php
    echo '<h2>Existing Files on your account:</h2>';
    // Define the full path to the folder whose contents you want to list
        
    $path "uploads/";
        
    // Open the directory
        
    $dir_handle = @opendir($path) or die("Error opening $path");
        
    // Loop through the files
    echo '<div style="border: 2px solid rgb(0, 0, 0);">'
    echo 
    '<table border=1>';    
    while (
    $file readdir($dir_handle)) {
          if(
    $file == "." || $file == ".." || $file == "index.php" ) { continue; }
    if (
    substr($file,($file 3)) != "raf") {
    //List all mp3 files
    echo '<tr>';
    echo 
    '<td>';
    echo 
    $file;
    echo 
    '</td>';
    $raffile fopen(("uploads/" . (substr($file,0,($file 3)) . "raf")), "r") or exit("Unable to 

    open file!"
    );
    //Output a line of the file until the end is reached
    while(!feof($raffile))
      {
    $cline fgets($raffile);
      echo 
    '<td>';
      echo (
    substr($cline,(strpos($cline,"=") + 1)));
      echo 
    '</td>';
      }
    fclose($raffile);
    echo 
    '</tr>';
    //List all mp3 files
    }
        }
    echo 
    '</table>';
    echo 
    '</div>';
    echo 
    '<br />';
    echo 
    '<BUTTON onclick="window.close();">Close Window</BUTTON>';
        
    // Close
        
    closedir($dir_handle);
    ?>
    There is a folder called uploads, in this folder there are different mp3 files. For each mp3 file there is an raf file with the same name. My code creates a table starting with the name of the mp3 file and then lists every line in the assosciating raf file in a new column.

    In most of the lines of the file a = sign can be found. I wrote some code to display only the text following the = sign.

    There are multiple lines in each raf file that that do not have = signs instead they start with [.

    Here is an example of an RAF file:

    Code:
    [raf]
    audioupdate=03/03/00-12:45:40
    audiotype=1
    
    [ann]
    user=false
    confirmplay=
    manualplay=true
    
    [alc]
    level=-3dB
    
    [autoplay]
    mins=0
    sequence=true
    
    [scheduling]
    commence=
    expire=
    timestart=00:00:00
    timeend=24:00:00
    daysofweek=127
    I do not want to list the [raf]/[ann]/[alc]/[autoplay]/[scheduling]. At the moment the table is listing all these lines but instead of, for example, [raf] it is being listed as raf]. Without the opening [.

    How do i filter out these lines starting with [?
    You shouldn't be using echo to produce HTML too.
    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.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: Filter Table

    Quote Originally Posted by visualAd View Post
    You shouldn't be using echo to produce HTML too.
    Why? What should i use instead a regular html page with php tags?

  9. #9
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Filter Table

    he means that instead of this:
    PHP Code:
     echo "<table><tr><td width=\"200\">$variable</td></tr></table>"
    you should do this:
    PHP Code:
    <table><tr><td width="200"><?php echo $variable?></td></tr><table>
    PHP is an embedded language, and should be treated as such. it's not exactly a means to output HTML.

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: Filter Table

    But what if i wanted the php code to recieve values from a form, $_POST? How can i set the action to a .html?

  11. #11
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Filter Table

    you can't post a form to an HTML file. that wouldn't do anything. HTML files are static and cannot be executed.

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