Reply
Outputting Database data into files.
Old 05-25-2005, 05:04 AM Outputting Database data into files.
lothop's Avatar
Extreme Talker

Posts: 229
Howdy yall?

Before starting my new project, I'm just wondering if it is actually possible to (with the click of a link/button) to output the data pulled from a database into a usable file, .pdf, .doc, .xls

To explain it in more depth;

The page viewer can fill out a search form eg. asking for a referrence# or date or company name. And it comes up with a list of invoices which are suitible for the search which was done. And as they view the invoice, they want to save it to a solo file and email it to someone.

They click on "export, save this invoice, yaddayadda" and it outputs the information fields (name,date,$$amount) to a file. Which then can be emailed out to the correct people.

I know how to do database searches, pulling data etc. But nothing as indepth as this.

Sooo yeah, just wondering if it was actually possible.

Thanks guys,
Greg
__________________
CUrrent sites working on...

http://www.Crashdays.com/
http://www.nzfiles.com/
lothop is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 05-25-2005, 06:51 AM
mtishetsky's Avatar
King Spam Talker

Posts: 1,054
Name: Mike
Location: Mataro, Spain
There are multiple PDF_* functions in PHP so you can generate PDF on the fly. I don't know what about DOC, but XLS can be generated very simply. Just output a correct HTML with tables and use headers (sent by header() function) to tell the browser you are sending XLS. These headers are:
1. Content-type: application/vnd.ms-excel
2. Content-disposition: attachment; filename="file.xls"
Most user systems with MS Office installed will recognize this as valid Excel file and will successfully open it.
__________________
Free Mobile Phone Themes

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 05-25-2005, 11:41 PM
lothop's Avatar
Extreme Talker

Posts: 229
Thanks for your reply, just to make sure im on the same wave length;

HTML Code:
<html>
<head>
<meta http-equiv="Content-Type" content="application/vnd.ms-excel">
<meta http-equiv="Content-disposition": attachment; filename="file.xls">
</head>
</html>
That as the header.

Then send the $variables through a form, but how to I process it at the end?
Probly wrong question to be asking here

I have to setup a pre-made .xls file and have it slot the information into it right?

(edit)
Using web queries I can gather information off the website, but the information wont be there unless the person is actually viewing the page right? So it will have to be told what variables are to be saved, and what the variables actually equal.
__________________
CUrrent sites working on...

http://www.Crashdays.com/
http://www.nzfiles.com/

Last edited by lothop : 05-25-2005 at 11:54 PM.
lothop is offline
Reply With Quote
View Public Profile
 
Old 05-26-2005, 03:24 AM
mtishetsky's Avatar
King Spam Talker

Posts: 1,054
Name: Mike
Location: Mataro, Spain
I didn't understand what $variables you are talking about, but you misunderstood me too. You should not write these headers into html, but should send them in your script using PHP header() function (RTFM please).

As about pre-made .xls - you also don't need it, you should create a template for HTML page (if you are familiar with templates) and then just output this HTML after sending headers as mentioned above.
__________________
Free Mobile Phone Themes

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 05-28-2005, 01:46 AM
lothop's Avatar
Extreme Talker

Posts: 229
Quote:
Originally Posted by mtishetsky
As about pre-made .xls - you also don't need it, you should create a template for HTML page (if you are familiar with templates) and then just output this HTML after sending headers as mentioned above.
But will that make it output it as a .xls file?
The $variables are the variables in the database. so ($variable)$ordernumber = 123

Then getting the ($ordernumber = 123) value to show up on a .xls file

Quote:
Originally Posted by mtishetsky
You should not write these headers into html, but should send them in your script using PHP header() function (RTFM please).
What would having it in the header do? Could I not just have it at the top of the page, in the html, Then run the PHP script from below?

Let me try to get my head around it;



This is at the top of the page which shows the searched/selected invoice information
PHP Code:
<?
require('inc/header.xls.php');
?>

<?
echo "Current invoice : $invoice";
echo 
"Current name : $iname";
echo 
"Current address : $address"
?>
(click here to send to .xls file for saving)
Then this is the header.xls.php page.
HTML Code:
<html>
<head>
<meta http-equiv="Content-Type" content="application/vnd.ms-excel">
<meta http-equiv="Content-disposition": attachment; filename="file.xls">
</head>
</html>
Hrmm, really wanna get this going. Thanks for ur help.
__________________
CUrrent sites working on...

http://www.Crashdays.com/
http://www.nzfiles.com/
lothop is offline
Reply With Quote
View Public Profile
 
Old 05-28-2005, 02:47 AM
mtishetsky's Avatar
King Spam Talker

Posts: 1,054
Name: Mike
Location: Mataro, Spain
1. First php script you create is a script that writes out standart html: blah blah blah, click here to download MS Excel file.
2. The link 'click here to download MS Excel file' points to second php script.
3. The second php script is something like that:
PHP Code:
<?
   header
("Content-type: application/vnd.ms-excel");
   
header("Content-disposition"attachmentfilename="file.xls");

   
$myData $myClass->getData();

?>

<table>
   <tr>
      <td><?= $myData->firstRow[0?></td>
      <td><?= $myData->firstRow[1?></td>
      <td><?= $myData->firstRow[2?></td>
   </tr>
   <tr>
      <td><?= $myData->secondRow[0?></td>
      <td><?= $myData->secondRow[1?></td>
      <td><?= $myData->secondRow[2?></td>
   </tr>
</table>
Did you get the idea now?
__________________
Free Mobile Phone Themes

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 05-28-2005, 06:42 AM
lothop's Avatar
Extreme Talker

Posts: 229
Ahhh yeeah now I understand.
I think the problem I was having was trying to understand the order in which to put it.


Thanks for all your help mtishetsky, I'll impletement it tommorow and let you know how I got on.

Thankyou!
Greg
__________________
CUrrent sites working on...

http://www.Crashdays.com/
http://www.nzfiles.com/
lothop is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Outputting Database data into files.
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.15013 seconds with 12 queries