WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
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 Index
Web Development Resources
Web Development Content
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
Mobile Dev World

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 : A script to generate a report from a valid mysql connection. The user has to supply which fields he wants to display in table. All properties are changable.
Categories : PHP, PHP Classes, Databases, MySQL, HTML and PHP Click here to Update Your Picture
Hasin Hayder
Date : Sep 02nd 2004
Grade : 3 of 5 (graded 26 times)
Viewed : 20494
File : 4007.zip
Images : No Images for this code example.
Search : More code by Hasin Hayder
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

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'>&nbsp;".$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'>&nbsp;".$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
MySQL database class
Categories : PHP, MySQL, Databases, PHP Classes
Required form fields that pull from MySQL database
Categories : PHP, HTML and PHP, Databases, MySQL
mySQL/PHP/search with multientry form and table output with colored rows
Categories : PHP, Beginner Guides, MySQL, HTML and PHP, Databases
Creating thumbnails from MySQL Blobs online
Categories : PHP, MySQL, Graphics, HTML and PHP, Databases
TAB_STRUCT Class: Is supporting Class for the DBXML Class
Categories : PHP, PHP Classes, MySQL, XML, Databases
Setting up InnoDB on MySQL and using Transactions Begin, Commit, Rollback in PHP.
Categories : PHP Classes, Databases, PHP, MySQL, InnoDB
Ajax PHP Tree (Left and Right) with MySQL
Categories : PHP, Databases, MySQL, AJAX, PHP Classes
YellowPages Content Grabber (PHP5 +)
Categories : PHP, PHP Classes, Regexps, Databases, MySQL
Storing / Retrieving pictures from database This can be used for banner / ads exchange. very useful for people developing big portal with ads in the site........
Categories : PHP, MySQL, Databases, HTML and PHP
Record Set Paging with PHP (RSP)
Categories : PHP, MySQL, Navigation, Databases, HTML and PHP
Alternating background color for HTML table rows
Categories : PHP, Databases, MySQL, HTML and PHP
Function to do live population of HTML's <Select> tag from a Table
Categories : PHP, MySQL, HTML and PHP, Databases
Editing the virtusertable and sendmail.cw via PHP3.0 and Mysql
Categories : MySQL, HTML and PHP, PHP, Databases