Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2010
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Modify Text files

    I figure out how to write all the entries from my database onto a text file.

    Code:
    header("Content-Type: text/plain");
    header("Content-Disposition: Attachment; filename=test.txt");
    header("Pragma: no-cache");
    exit;
    How do I modify the text file??
    Each entries (or row) have 5 elements in it and there are multiple entries in my database.
    How do I write each elements follow by a comma onto a text file? Each row in the database would have a new line in my text file as well.

    tks

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,206
    Thanks
    23
    Thanked 605 Times in 604 Posts
    I had an old file, dusted it off. It caused me a lot of nightmares so wrote from scratch.

    PHP Code:
    <?php
    require('inc/DB_connect.php');   // Your connect to database
    unlink('MyFile.cvs');            // used this because I was writing the file hunderds of times. You may not need
    $fp fopen("MyFile.cvs""w");  // Opened the file for writting
    $DbFile 'clan_members';        // Put the name of your table here

    $result mysql_query("SELECT * FROM $DbFile");
    $row mysql_fetch_assoc($result);

    $line '';
    $comma '';
    foreach (
    $row as $name => $value)
    {
        
    $line .= $comma '' str_replace('''""'$name);
        
    $comma ',';
    }
    $line .= '\n';
    fputs($fp$line);

    mysql_data_seek($result0);
    $line '';
    while(
    $row mysql_fetch_assoc($result))
    {
        
    $comma '';
        foreach (
    $row as $name => $value)
        {
            
    $line .= $comma str_replace('''""'$value);
            
    $comma ',';
        }
        
    $line .= '\n';
    }
    fputs($fp$line);
    echo 
    $line;
    fclose($fp);
    ?>


  •  

    Posting Permissions

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