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
https://forums.phpfreaks.com/topic/128017-php-form-to-excel-document/
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";
?>

Archived

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

×
×
  • 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.