download csv php mysql

Solutions on MaxInterview for download csv php mysql by the best coders in the world

showing results for - "download csv php mysql"
Elizabeth
12 Feb 2018
1CREATE TABLE `users` (
2  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
3  `username` varchar(80) NOT NULL,
4  `name` varchar(50) NOT NULL,
5  `gender` varchar(10) NOT NULL,
6  `email` varchar(70) NOT NULL
7) ENGINE=InnoDB DEFAULT CHARSET=latin1;
8
9=========================================================
10// this config.php
11<?php
12$host = "localhost"; /* Host name */
13$user = "root"; /* User */
14$password = ""; /* Password */
15$dbname = "tutorial"; /* Database name */
16
17$con = mysqli_connect($host, $user, $password,$dbname);
18// Check connection
19if (!$con) {
20 die("Connection failed: " . mysqli_connect_error());
21}
22
23
24=================================================================
25// prints contents of db to a table with an export button
26<?php 
27include "config.php"; // Database connection file
28?>
29
30<div class="container">
31 
32 <form method='post' action='download.php'>
33  <input type='submit' value='Export' name='Export'>
34 
35  <table border='1' style='border-collapse:collapse;'>
36    <tr>
37     <th>ID</th>
38     <th>Username</th>
39     <th>Name</th>
40     <th>Gender</th>
41     <th>Email</th>
42    </tr>
43    <?php 
44     $query = "SELECT * FROM users ORDER BY id asc";
45     $result = mysqli_query($con,$query);
46     $user_arr = array();
47     while($row = mysqli_fetch_array($result)){
48      $id = $row['id'];
49      $uname = $row['username'];
50      $name = $row['name'];
51      $gender = $row['gender'];
52      $email = $row['email'];
53      $user_arr[] = array($id,$uname,$name,$gender,$email);
54   ?>
55      <tr>
56       <td><?php echo $id; ?></td>
57       <td><?php echo $uname; ?></td>
58       <td><?php echo $name; ?></td>
59       <td><?php echo $gender; ?></td>
60       <td><?php echo $email; ?></td>
61      </tr>
62   <?php
63    }
64   ?>
65   </table>
66   <?php 
67    $serialize_user_arr = serialize($user_arr);
68   ?>
69  <textarea name='export_data' style='display: none;'><?php echo $serialize_user_arr; ?></textarea>
70 </form>
71</div>
72    
73    
74    
75    =============================================================
76  //Create a new download.php file -- code below//  
77    
78    <?php
79$filename = 'users.csv';
80$export_data = unserialize($_POST['export_data']);
81
82// file creation
83$file = fopen($filename,"w");
84
85foreach ($export_data as $line){
86 fputcsv($file,$line);
87}
88
89fclose($file);
90
91// download
92header("Content-Description: File Transfer");
93header("Content-Disposition: attachment; filename=".$filename);
94header("Content-Type: application/csv; "); 
95
96readfile($filename);
97
98// deleting file
99unlink($filename);
100exit();
queries leading to this page
export mysql data to csv file using phpexport data from mysql to csv in phphow to download csv in phpcsv download phpdownload csv file in php examplephp export mysql database to csv scriptdownload csv on button click from php mysqlhow to import csv file in php mysqlhow to download csv file in phpphp create csv using mysql dataphp file download csvphp download as csvexport mysql database to csv phpphp download csv not from mysql how to create csv to mysql database tables using phpdownload link csv phpdownload csv in phpdownload csv code in phpphp download csv from tablephp export mysql data to csv filehow to export data from mysql database to csv using phpcsv download in phpsql to csv phpphp export db to csvphp write sql table to csvphp export table to csvsave data to csv phpphp create export file csv from sql querydownload data in csv format in phpphp sql dump csvhow to create a csv file in php with sql queryexport csv to database phpexport mysql to csv php scriptphp mysql query export to csvquery to csv phpdownload csv file php mysqldownload data as csv phpphp export mysql to csv downloadhow to download csv file from database using phpphp save mysql result to csvphp export to csv from mysql export to csv in phphow to upload csv to mysqldownload csv using phpphp mysql to csvphp download csvphp mysql query to csvphp export mysql to csvphp download sql to csvexport table data using phpsql to csv in phpphp upload csv to mysqlhow to export table data in csv file using phpmyadmin in phpphp download csv from queryhow to download csv from phpsql server table into csv file phpexport mysql csv phpphp export to csvdownload php csvphp download csv file php mysql download csvhow to export data to csv file in phpexport to csv php mysqlphp download csv from mysqldownload csv file in phpdownload csv file phphow to export csv to mysql phpexport table in mysql in csv in mysqli commanddownload csv format from sql query phpphp code to download csv file and insert into mysqldownload csv php mysqlphp export sql to csvexport csv file in php mysqlphp download csv file from serverphp mysql table to csvcsv file from sql query phpphp mysql export to csv downloadexport table mysql csv phpphp to download csv for phpdownload as csv in phpget data from sql into csv phpphp download csv file exampleexport csv mysql phpdownload csv file from mysql with phpphp code to download csv file and upload to mysqlphp export database to csvphp download data as csvphp code to export data to csv filehow to download created csv in phpexport data in csv in phpphp download mysql table as csvimport csv file into mysql phpcsv export download in phpphp sql table to csvphp export mysql query to csvdownload csv php mysql