Activity Stream
48,167 MEMBERS
6841 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 3 of 3
  1.     
    #1
    Member

    Default PHP - MySQL query to CSV export

    Hi

    I need some advise how to achieve this.. there is a link "Click here to generate CSV" when someone clicks that link, it should execute a query and export that sql query result to a CSV file..

    any guidance pls?

    Sam
    ElitePirate Reviewed by ElitePirate on . PHP - MySQL query to CSV export Hi I need some advise how to achieve this.. there is a link "Click here to generate CSV" when someone clicks that link, it should execute a query and export that sql query result to a CSV file.. any guidance pls? Sam Rating: 5




  2.   Sponsored Links

  3.     
    #2
    Member

  4.     
    #3
    Member
    Website's:
    tehMoviez.com 0Senes.com GeekFaceGames.com
    google says:
    PHP Code: 
    mysql_connect($server$login$password);
    mysql_select_db($db);

    $fp fopen($filename"w");

    $res mysql_query("SELECT * FROM $table");

    // fetch a row and write the column names out to the file
    $row mysql_fetch_assoc($res);
    $line "";
    $comma "";
    foreach(
    $row as $name => $value) {
        
    $line .= $comma '"' str_replace('"''""'$name) . '"';
        
    $comma ",";
    }
    $line .= "\n";
    fputs($fp$line);

    // remove the result pointer back to the start
    mysql_data_seek($res0);

    // and loop through the actual data
    while($row mysql_fetch_assoc($res)) {
       
        
    $line "";
        
    $comma "";
        foreach(
    $row as $value) {
            
    $line .= $comma '"' str_replace('"''""'$value) . '"';
            
    $comma ",";
        }
        
    $line .= "\n";
        
    fputs($fp$line);
       
    }

    fclose($fp); 

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. mysql query to export database
    By lenney in forum IP.Board
    Replies: 4
    Last Post: 7th May 2011, 03:43 PM
  2. MySql Query
    By GoPantheoN in forum Web Development Area
    Replies: 5
    Last Post: 8th Mar 2011, 02:09 PM
  3. mysql query help ($5 reward)
    By tdsii in forum Web Development Area
    Replies: 20
    Last Post: 10th Jan 2011, 11:52 PM
  4. WordPress database error MySQL server has gone away for query
    By blur88 in forum Webmaster Discussion
    Replies: 10
    Last Post: 27th May 2010, 08:43 PM
  5. Speed Up Your Web Site With MySQL Query Caching
    By BlaZe in forum Technical and Security Tutorials
    Replies: 1
    Last Post: 4th Nov 2009, 03:11 PM

Tags for this Thread

BE SOCIAL