Jump to content

Recommended Posts

csv file is fairly easy to create with PHP. And of course Excel can open any csv file quite easily. The data won't look pretty, but that's not what it's supposed to do. Um, if theres a tutorial on EXACTLY what you want to do? I'm not sure.

 

But you will want to become familiar with PHP's fopen, and all that for file handling. And explode() and implode() you will probably use. The information your saving to the csv files is from MySQL or some other source, and I'm assuming you can read from there.

if suppose i have a mysql database

 

and i want to get data from mysql & then make CSV file for download so now how can i do that ?

 

can u help me out ?

 

 

No need to waste space on your server's HD by saving a file:

 

<?php
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename='foo.csv'");
$data="col1, col2, col3, \n";
echo $data;
?>

 

Best,

 

Patrick

myharshdesigner, please provide the code you have already tried. if you wish for someone to write the complete code for you, then try posting for paid help in the Freelance board. A Google search for PHP and CSV will provide you with the resources - there's no point getting code if you're not going to be able to understand it, as you'll end up with tonnes more problem down the line.

<?php
$data = "";
$row = 'first value,';
$row .= 'second value,';
$row .= 'third value';
$data .= $row."\n";

$row = 'fourth value,';
$row .= 'fifth value,';
$row .= 'sixth value';
$data .= $row."\n";

// Output the headers to download the file
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=log.csv");
header("Pragma: no-cache");
header("Expires: 0");
echo $data;
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.