Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6093265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:32:24+00:00 2026-05-23T12:32:24+00:00

I am attempting to export mysql data into excel. I have tried the phpexcel

  • 0

I am attempting to export mysql data into excel. I have tried the phpexcel class, and cannot use this on my host, as they do not have the zip function installed. I cannot export the data to csv, as the client ‘wants to see purty colors…’ so formatting is a must. So it looks like I am stuck building a table to pass to Excel. (unless anyone has any ideas on other classes!)

I am having an issue with the code, it exports just fine to excel and the formatting is correct for the first row. On all subsequent rows, all data is ‘dumped’ into one cell.
Here is the code:

$table .= '<table border="0" cellpadding="0" cellspacing="0"><tr>'; 
        $table .= '<td style="background-color:#000099;color:#FFFFFF;">Date</td>';
        $table .= '<td style="background-color:#000099;color:#FFFFFF;">Name</td>';
        $table .= '<td style="background-color:#000099;color:#FFFFFF;">Address</td>';
        $table .= '<td style="background-color:#000099;color:#FFFFFF;">City</td>';
        $table .= '</tr>';
        while($row=mysql_fetch_array($result)){
        $table .= '<tr>';
        $table .= '<td style="background-color:#FFFCCC">'.$row['date'].'</td>';
        $table .= '<td style="background-color:#FFFCCC">'.$row['name'].'</td>';
        $table .= '<td style="background-color:#FFFCCC">'.$row['address'].'</td>';
        $table .= '<td style="background-color:#FFFCCC">'.$row['city'].'</td>';
        $table .= '</tr>';
        $table .= '</table>';
        }
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=Itinerary-$today.xls "); 
header("Content-Transfer-Encoding: binary ");
echo $table;

Appreciate any thoughts anyone can share on this subject!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:32:25+00:00Added an answer on May 23, 2026 at 12:32 pm

    Try moving this line:

    $table .= '</table>';
    

    to outside the loop.

    The last few lines of the loop should looke like:

        $table .= '</tr>';
    }
    $table .= '</table>';
    

    You opened a table before the loop, you should close the table after the loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Attempting to use the data series from this example no longer passes the JSONLint
Summary: When attempting to use marshalling to pass string data into a C++ DLL
I'm trying to export data from a web app into excel, but there is
I am attempting to export a query from MS Access into MS Excel in
Attempting to use XStream's JavaBeanConverter and running into an issue. Most likely I'm missng
What I am attempting to do is have an end CSV file like this:
I am attempting to use the shared part creation policy for a MEF export.
Attempting to insert an escape character into a table results in a warning. For
I have a class A which has the following: public class A { [Import(typeof(IMyService)]
I've created a model with MySQL Workbench and am now attempting to install it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.