WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel Click here to Update Your Picture
MA Razzaque Rupom
Date : Jun 17th 2006
Grade : 3 of 5 (graded 10 times)
Viewed : 26915
File : 4423.zip
Images : No Images for this code example.
Search : More code by MA Razzaque Rupom
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

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
Browser Detecor Class
Categories : PHP Classes, PHP, HTML
Allows you to parse a deliniated string and put the individual fields in a SELECT option in a form
Categories : HTML, PHP, Strings
How To Create a PDF Using PHP
Categories : PHP, PDF, PHP Classes, HTML and PHP
Url To Pdf Report By Remote Application
Categories : PHP, PHP Classes, PDF, CURL
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
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
Paginator - a class that can help you to split MySQL database query result sets to pages.
Categories : MySQL, Databases, HTML, PHP
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
Formit 1.0. PHP Very easy to implement form-template(s) to email script. Works with multiple templates and HTML-format email. Only one file!
Categories : PHP, Email, HTML
This script shows you the 7th latest php items from the mailing list archive on zend.com
Categories : HTML, HTML and PHP, HTTP, PHP
GonxTabs : Create elegant HTML tabs based interface
Categories : Navigation, HTML, HTML and PHP, PHP
Excel class in PHP
Categories : PHP, PHP Classes, Excel
class formHTML build your HTML Forms from PHP
Categories : PHP, PHP Classes, HTML and PHP, HTML