|
|
|
This class generates HTML, PDF and CSV Reports from MySQL Query.
Here's how it works:
For HTML Report:
| - Executes given query and generates HTML report first
- Appends query reports to previous report(if any)
- Creates an HTML file and store that report-data as HTML report | |
For PDF Report:
| - Gets URL of the resultant HTML report
- Creates PDF report for that HTML report by using remote application | |
For CSV Report:
| - Executes given query and prepares CSV headers from result resource
- Traverses result resource and prepares CSV compatible text
- Outputs that data (download prompt) | |
For Remote PDF Application, I have used html2ps and html2pdf (supplied by http://www.tufat.com/script19.htm). It is 100% FREE for commercial AND non-commercial use! It renders pages as PDF documents and PostScript files. I have deployed this application to phpResource(http://groups.yahoo.com/group/phpresource/) group's server for easy and reliable access. My special thanks goes to phpResource group.
Ussage Example
| <?php
/**
* Query2Report Generator Class
*
* @author : MA Razzaque Rupom <rupom_315@yahoo.com>, <rupom.bd@gmail.com>
* Moderator, phpResource (http://groups.yahoo.com/group/phpresource/)
* Blog: http://www.rupom.info
* @version : 1.0
* @date : 06/17/2006
* Purpose : Generating HTML, PDF and CSV Reports from MySQL Query
*/
ob_start();
ini_set('display_errors','Off');
require_once('Query2Report.class.php');
//make sure the DB connection is ok
mysql_connect('localhost','root','');
mysql_select_db('test');
//queries whose output will be used as report data
$query_1 = "SELECT * FROM book";
$query_2 = "SELECT title,author FROM book";
$query_3 = "SELECT book_id,publisher,reader FROM book";
$obj = new Query2Report();
//sets absolute path where HTML report file will be saved (should be under doc_root so that its URL can be set)
$obj->setHtmlPath("/projects/rupom/phpclasses/sql2pdfreport/first_test.html"); //change this according to your Path
//sets URL of the HTML report file
$obj->setHtmlUrl("http://localhost/phpclasses/sql2pdfreport/first_test.html");//change this according to your URL
//inits row colors. colors will be repeated automatically
$obj->initRowColors(array('#336699','#f5f5f5'));
//generates report from $query_1
$obj->generateReport($query_1);
//changes row colors for the second report.
$obj->initRowColors(array('#f8f8f8','#336699','#353535'));
//generates report from $query_2 and appends it to previous report data
$obj->generateReport($query_2);
//generates report from $query_3 and appends it to previous report data
$obj->generateReport($query_3);
//gets the pdf report of all the report data
$obj->getPdfReport();
//generates CSV report
$obj->generateCsvReport($query_1);
//gets CSV report
$obj->getCsvReport();
?> | | |
|
| PHP-PDF-Converter Categories : PHP, Excel, PDF, Microsoft Word, COM | | | Free PDF file creation using PHP. Categories : PDF, PHP | | | color codes for positive and negative numbers Categories : PHP, MySQL, Databases, HTML | | | Parses HTTP_USER_AGENT so that you can customize your site to different browsers Categories : HTML, PHP, Complete Programs | | | FormWizard reads a mysql table and generates automatically
a html formular in a html-table Categories : PHP, MySQL, HTML | | | Allows you to parse a deliniated string and put the individual fields in a SELECT option in a form Categories : HTML, PHP, Strings | | | Browser Detecor Class Categories : PHP Classes, PHP, HTML | | | BBCode Formatting String Categories : PHP, HTML, Regexps, Arrays | | | Display Slashdot headers on your own site Categories : HTML and PHP, HTML, PHP | | | webcam cam view image ispy browser independant Categories : Graphics, HTML, HTML and PHP, PHP | | | Builds JavaScript that updates the contents of one selector based on another. Categories : HTML, Java Script, PHP, Complete Programs, General | | | ASCII To HTML Converter Categories : PHP, HTML, ASCII | | | Spreadsheet Date Calculations in PHP Categories : PHP, Date Time, Excel | | | How to preset a text string in a textarea input field Categories : HTML, HTML and PHP, PHP, Beginner Guides | | | Automatic generation of HTML code for a table. OO interface. Can define colspan, rowspan, table style, cell style, and data style. Simple, but
effective. Categories : PHP, PHP Classes, HTML, HTML and PHP | |
|
|
|