Jump to content

php form to excel document


will2002

Recommended Posts

hi

 

I have an sql query which prints output to a html form.

 

i then use header code to save the results of this as a microsoft excel document.

All of the code is working fine.

 

The only problem is that everything on the page is being saved in the excel file such as images, search fields, buttons etc.

is there a way to just take the information from the query without the rest of the page coming aswell

 

any help would be greatly appreciated.

 

here is the section of code minus the html form and html table data, there is a lot of html code on the full page for navigation and visual purposes.

 

hi

I have an sql query which prints output to a html form.

i wish to be able to send the results of this to a microsoft excel document.
All of the code is working fine.

The only problem is that everything on the page is being saved in the excel file such as images, search fields, buttons etc.
is there a way to just take the information from the query without the rest of the page coming aswell

any help would be greatly appreciated.

here is the section of code minus the html form and html table data, there is a lot of html code on the full page for navigation and visual purposes.

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL & ~E_NOTICE);
if(isset($_POST['login'])){
if($dbc = @mysql_connect('localhost', '', '')){
if(!$dbc = @mysql_select_db('employees')){
die("<p> Could not select the database because:'.mysql_error().'</p>");
}
}else{
die("<p> Could not select the database because:'.mysql_error().'</p>");
}
$query = "SELECT * FROM timesheet WHERE day='{$_POST['dt']}' AND month='{$_POST['month']}'AND year='{$_POST['year']}'";
if ($r = mysql_query($query)){
while ($row =mysql_fetch_array($r)){
echo "<tr><td>{$row['num']}</td><td>{$row['name']}</td><td>{$row['norm']}</td><td>{$row['normhalf']}</td><td>{$row['normdouble']}</td><td>{$row['normquarter']}</td><td>{$row['normthird']}</td><td>{$row['hol']}</td><td>{$row['hol1']}</td><td>{$row['hol2']}</td><td>{$row['hol3']}</td><td>{$row['remarks']}</td></tr>";
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition:filename=file.xls");
ob_end_flush();
?>

Link to comment
Share on other sites

I'd recommend generating your Excel file in a separate script and linking to it...

 

<?php
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition:filename=file.xls");

$r = mysql_query("SELECT * FROM `foo`") or die(mysql_error());
while($rr = mysql_fetch_assoc($r)) echo "\"$rr[foo_0]\",\"$rr[foo_1]\",\"$rr[foo_2]\"\n";
?>

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.