Skip to main content

PHP export csv

12th October, 2022

Updated: 12th October, 2022

    <?php
    
    require('assets/php/connect.php');
    
    $query = "SELECT name, fields, here FROM users";
    $result = mysql_query($query);
    
    $radioresults = array();
    $i = 0;
    while($row = mysql_fetch_array($result))
    {
        $rawradioresults = $row['radioresults'];
        $radioresults = explode("/",$rawradioresults);
    
        $added = $row['added'];
        $datestring1 = strtotime($added);
        $added = date( "j F Y g:i a", $datestring1);
    
        $improvements = $row['improvements'];
    
        $content[$i] = $row['country'].'|'.$radioresults[0].'|'.$radioresults[1].'|'.$radioresults[2].'|'.$radioresults[3].'|'.$radioresults[4].'|'.$radioresults[5].'|'.$improvements.'|'.$added.'';
    
        $i++;
    }
    
    
    $file = fopen("evaluationresults.csv", "w");
    $x = 0;
    foreach ($content as $line) {
      fputcsv($file,explode('|',$line));
     }
    
    fclose($file);
    $exported = true;
    header('location: evaluationresults.csv');
    
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=".$filename);
    echo $data;
    
    ?>

    2d03ed06-db24-41e1-bbe9-72179462c06f

    Created on: 12th October, 2022

    Last updated: 12th October, 2022

    Tagged With: