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 : 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 32 times)
Viewed : 35423
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  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
Simple Mini Poll class library (SimPoll)
Categories : PHP, PHP Classes, Databases, MySQL, Complete Programs
Powerful php/mysql Pagination for up to 6 URL Params
Categories : PHP, PHP Classes, Databases, MySQL, Navigation
PHP and MySQL scripting for Muyltiple CheckBoxes
Categories : HTML and PHP, MySQL, Databases, PHP
DDN FFA Network Script
Categories : PHP, MySQL, Complete Programs, HTML and PHP, Databases
Simple usersOnline class - keep track of how many users are online on your site
Categories : PHP, PHP Classes, Databases, MySQL
PostGreSQL and MySQL 2 in 1 db Manager
Categories : PHP, PHP Classes, Databases, PostgreSQL, MySQL
phpMyDataGrid 2007
Categories : AJAX, PHP Classes, MySQL, Databases, HTML and PHP
dynamic table columns
Categories : PHP, HTML and PHP, Arrays, Databases, MySQL
Pull Down Surfing - Surf on Change
Categories : Java Script, MySQL, HTML and PHP, PHP, Databases
[PHP5] aDB PDO LIKE Database Abstraction. Switch easily from one db server to another, strong errors management, manage transactions, queries preparation and more.
Categories : PHP, PHP Classes, Databases, MS SQL Server, MySQL
A PHP useradmin for MySQL. Uploading is easy. The only thing you need is PHP and MySQL installed!
Categories : MySQL, Databases, PHP, HTML and PHP
Password reminder
Categories : PHP, PHP Classes, Databases, MySQL, Mail
Functions for loading images into a MySQL database and displaying them.
Categories : Graphics, HTML and PHP, MySQL, PHP, Databases
Online Automatic Class Generator for MySQL Tables
Categories : PHP, PHP Classes, Classes and Objects, Databases, MySQL