Jump to content

Archived

This topic is now archived and is closed to further replies.

gterre

Export mysql select query into excel

Recommended Posts

How do i do this? according to people online i'm supposed to right click the table and select export to microsoft excel, however when I do this it says, the webquery returned no data. I'm guessing because i'm using sessions. Is there any way where i can put a link for example ..export.. and when the user clicks on it, it will export into an excel document.. I am using the PHP api.


Thank you :)

Share this post


Link to post
Share on other sites
well, you can always simply generate a CSV or tab delimited file with any query results:
[code]
<?php
$sql = mysql_query("SELECT * FROM tableName");
$rc = mysql_num_rows($sql);
if ($rc > 0) {
  // at least one row returned:
  header("Content-type: application/txt");
  header("Content-Disposition: attachment; filename=myTabbedFile.txt");
  while ($row = mysql_fetch_array($sql)) {
    // create row with quoted text
    $row = implode('\t', $row) . "\n";
    echo $row;
  }
  exit(); // will keep the close of the html page being included
}
?>
[/code]

hope this helps

Share this post


Link to post
Share on other sites

×

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.