• 0

CSV, PHP and more!


Question

Hey there fellow Neowinians! :)

I have an SQL table on a database that I want to export into a CSV file. Now I googled arround a bit and I found some PHP code that worked fine. The problem is this, when I run the PHP code in a file on it's own, IE prompts me asking whether I want to Open or Save the file (which is what I want it to do). However, when I integrate the code into an existing PHP page that I have, it just dumps the text to the screen (which is what I want to avoid!). Is there anyway I can have IE force a download of a CSV file for Excel? I'll paste the code below so you can see...

<edit> No matter what code I use to try and force a download, I can't seem to get IE to stop displaying the data in the bowser and force a download! HELP! </edit>

<?

if ($_POST['submit'])

{

header("Content-Disposition: attachment; filename=testing.csv");

include_once ("./settings.php"); //login & password info here

$link = mysql_connect($host,$user,$password); // connect to database

mysql_select_db("$base");

$errorList = array();

$count = 0;

if (sizeof($errorList) == 0)

{

? //START FILLING IN THE FIELDNAME ON TOP OF EXCEL SHEET.

? $fieldSql = "SHOW FIELDS FROM Spinal_Tech_Timecards_DB";

? $getFieldInfo = mysql_query($fieldSql);

? $i = 0;

?

? while ($row = mysql_fetch_array($getFieldInfo))

? {

? echo $row['Field'] . ",";

? }

? echo ("\n");

?

? //START FILLING IN THE ROWS IN EXCEL SHEET.

? $sql = "SELECT * FROM `Spinal_Tech_Timecards_DB` WHERE `Spinal Tech Approved` = 'Y' AND `Payroll Approved` = 'Y' ";

? $getInfo = mysql_query($sql);

? while($row = mysql_fetch_array($getInfo, MYSQL_ASSOC))

? {

?  while (list($key, $value) = each($row))

?  {

?  echo ("$value" . ",");

?  }

?  echo ("\n");

? }

? mysql_close($conn);

? echo "success!";

}

else

{

? echo "crap!";

}

Edited by ECEGatorTuro
Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.