|
|
|
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 | | | How To Create a PDF Using PHP Categories : PHP, PDF, PHP Classes, HTML and PHP | | | Popup Menu 0.5, popup, select, html, state-maintaing Categories : HTML, PHP, HTML and PHP | | | 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 | | | Url To Pdf Report By Remote Application Categories : PHP, PHP Classes, PDF, CURL | | | How to know which input button of type image was pressed in a form with
multiple image buttons (_x and _y) in PHP? Categories : PHP, Variables, HTML | | | How to preset a text string in a textarea input field Categories : HTML, HTML and PHP, PHP, Beginner Guides | | | PDF_add_annotation -- Deprecitad: Adds annotation Categories : PHP, PHP Functions, PDF | | | How to use regular expressions to get the list of links from an HTML page Categories : PHP, Regexps, HTML, HTML and PHP | | | Paginator - a class that can help you to split MySQL database query result sets to pages. Categories : MySQL, Databases, HTML, PHP | | | How to access MS Excel spread sheets from PHP Categories : PHP, Excel, ODBC, Databases | | | Browser Detecor Class Categories : PHP Classes, PHP, HTML | | | Real simple example of removing HTML tags from text then changing \n (new line) to <br>. Could be used in a forum for instance. Categories : HTML, PHP, HTML and PHP, Beginner Guides | | | GonxTabs : Create elegant HTML tabs based interface Categories : Navigation, HTML, HTML and PHP, PHP | |
|
|