Jump to content


Export mysql select query into excel

  • Please log in to reply
1 reply to this topic

#1 gterre

  • Members
  • PipPip
  • Member
  • 27 posts

Posted 18 September 2006 - 06:53 PM

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 :)

#2 obsidian

  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 18 September 2006 - 07:06 PM

well, you can always simply generate a CSV or tab delimited file with any query results:
$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

hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users