|
|
|
|
|
|
| |
Class Name : phpReportGenerator
Version : 1.0
Written By : Hasin Hayder
Start Date : 4th July, 2004
Copyright : Systech Digital.
| <?php
class phpReportGenerator
{
var $mysql_resource;
var $header;
var $foolter;
var $fields = array();
var $cellpad;
var $cellspace;
var $border;
var $width;
var $modified_width;
var $header_color;
var $header_textcolor;
var $header_alignment;
var $body_color;
var $body_textcolor;
var $body_alignment;
var $surrounded;
var $font_name;
function generateReport()
{
$this->border = (empty($this->border))?"0":$this->border;
$this->cellpad = (empty($this->cellpad))?"1":$this->cellpad;
$this->cellspace = (empty($this->cellspace))?"0":$this->cellspace;
$this->width = (empty($this->width))?"100%":$this->width;
$this->header_color = (empty($this->header_color))?"#FFFFFF":$this->header_color;
$this->header_textcolor = (empty($this->header_textcolor))?"#000000":$this->header_textcolor;
$this->header_alignment = (empty($this->header_alignment))?"left":$this->header_alignment;
$this->body_color = (empty($this->body_color))?"#FFFFFF":$this->body_color;
$this->body_textcolor = (empty($this->body_textcolor))?"#000000":$this->body_textcolor;
$this->body_alignment = (empty($this->body_alignment))?"left":$this->body_alignment;
$this->surrounded = (empty($this->surrounded))?false:true;
$this->modified_width = ($this->surrounded==true)?"100%":$this->width;
$this->cellpad = (empty($this->font_name))?"Arial":$this->font_name;
//echo "modified_width : ".$this->modified_width."<br>";
if (!is_resource($this->mysql_resource))
die ("User doesn't supply any valid mysql resource after executing query result");
/*
* Lets calculate how many fields are there in supplied resource
* and store their name in $this->fields[] array
*/
$field_count = mysql_num_fields($this->mysql_resource);
$i = 0;
while ($i < $field_count)
{
$field = mysql_fetch_field($this->mysql_resource);
$this->fields[$i] = $field->name;
$this->fields[$i][0] = strtoupper($this->fields[$i][0]);
$i++;
}
/*
* Now start table generation
* We must draw this table according to number of fields
*/
echo "<b><i>".$this->header."</i></b>";
echo "<P></P>";
//Check If our table has to be surrounded by an additional table
//which increase style of this table
if ($this->surrounded == true)
echo "<table width='$this->width' border='1' cellspacing='0' cellpadding='0'><tr><td>";
echo "<table width='$this->modified_width' border='$this->border' cellspacing='$this->cellspace' cellpadding='$this->cellpad'>";
echo "<tr bgcolor = '$this->header_color'>";
//Header Draw
for ($i = 0; $i< $field_count; $i++)
{
//Now Draw Headers
echo "<th align = '$this->header_alignment'><font color = '$this->header_textcolor' face = '$this->font_name'> ".$this->fields[$i]."</font></th>";
}
echo "</tr>";
//Now fill the table with data
while ($rows = mysql_fetch_row($this->mysql_resource))
{
echo "<tr align = '$this->body_alignment' bgcolor = '$this->body_color'>";
for ($i = 0; $i < $field_count; $i++)
{
//Now Draw Data
echo "<td><font color = '$this->body_textcolor' face = '$this->font_name'> ".$rows[$i]."</font></td>";
}
echo "</tr>";
}
echo "</table>";
if ($this->surrounded == true)
echo "</td></tr></table>";
}
}
?> | |
Usage Example
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>PHP Report Generator</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
include_once("phpReportGen.php");
$prg = new phpReportGenerator();
$prg->width = "100%";
$prg->cellpad = "0";
$prg->cellspace = "0";
$prg->border = "1";
$prg->header_color = "#465584";
$prg->header_textcolor="#FFFFFF";
$prg->body_alignment = "left";
$prg->body_color = "#D1DCEB";
$prg->body_textcolor = "#000000";
$prg->surrounded = '1';
//$prg->font_name = "Boishakhi";
mysql_connect("localhost","root","root");
mysql_select_db("company");
$res = mysql_query("select name, age, area from table1 where age>20");
$prg->mysql_resource = $res;
//$prg->title = "Test Table";
$prg->generateReport();
?>
</body>
</html> | | |
|
| phpFormGenerator for Dynamic Form Generation from MySQL Categories : PHP, PHP Classes, MySQL, Databases, HTML and PHP | | | Message of the Day - Random Message (Needs MySQL!) Categories : Databases, HTML and PHP, PHP, MySQL | | | Alternating background color for HTML table rows Categories : PHP, Databases, MySQL, HTML and PHP | | | A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL | | | Automatically printing the contents of an sql table in MySQL. Categories : MySQL, PHP, HTML and PHP, Databases | | | MySQL Handler Categories : PHP, Databases, MySQL, Classes and Objects, PHP Classes | | | Powerful php/mysql Pagination for up to 6 URL Params Categories : PHP, PHP Classes, Databases, MySQL, Navigation | | | PostGreSQL and MySQL 2 in 1 db Manager Categories : PHP, PHP Classes, Databases, PostgreSQL, MySQL | | | Pull Down Surfing - Surf on Change Categories : Java Script, MySQL, HTML and PHP, PHP, Databases | | | Password reminder Categories : PHP, PHP Classes, Databases, MySQL, Mail | | | Dynamically generated pop-ups (Select items) Categories : PHP, HTML and PHP, MySQL, Databases | | | MySQL Class to ease Database connectivity Categories : MySQL, PHP Classes, Databases, PHP | | | Creating thumbnails from MySQL Blobs online Categories : PHP, MySQL, Graphics, HTML and PHP, Databases | | | Record Set Paging with PHP (RSP) Categories : PHP, MySQL, Navigation, Databases, HTML and PHP | | | usercounter class Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables | |
|
|
|