Jump to content

Export mysql select query into excel


gterre

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 :)
Link to comment
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
Link to comment
Share on other sites

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.