Generating MySqlReports using PHP classes
Posted: Mon Jun 29, 2009 10:48 pm
Hi everybody,
Can u people please help me. i m genarating mysql database reports using this code.
but this code is working on my local PC windows O/S but when i am trying to run this
code on linux server its not genrating reports. it showing followng error.
"User doesn't supply any valid mysql resource after executing query result"
Please help me.
<?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>";
}
}
?>
_______________________________________________________________________________
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Reports</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<center><td width="850" height="118" colspan="2" align="left" valign="top" bgcolor="#FFFFFF"><img src="../images/header.gif" width="850" height="118" /></td> </center>
<a STYLE=text-decoration:none href="Chart.php"><font color=blue size="2"><b> Back</b></font></a><br><br>
<center><h2><font color="blue">Year-wise Report</font></h2></center>
<?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","bbbn");
mysql_select_db("iasb_ims");
$res = mysql_query("select Event_id, Event_Type, Date_Event, Time_Event, Location, Desc_Event, Corrective_Action_Taken from client_report");
//$res = mysql_query("select Event_Type, age, area from table1 where age>20");
$prg->mysql_resource = $res;
//$prg->title = "Test Table";
$prg->generateReport();
?>
</body>
</html>
Thanking you,
Can u people please help me. i m genarating mysql database reports using this code.
but this code is working on my local PC windows O/S but when i am trying to run this
code on linux server its not genrating reports. it showing followng error.
"User doesn't supply any valid mysql resource after executing query result"
Please help me.
<?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>";
}
}
?>
_______________________________________________________________________________
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Reports</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<center><td width="850" height="118" colspan="2" align="left" valign="top" bgcolor="#FFFFFF"><img src="../images/header.gif" width="850" height="118" /></td> </center>
<a STYLE=text-decoration:none href="Chart.php"><font color=blue size="2"><b> Back</b></font></a><br><br>
<center><h2><font color="blue">Year-wise Report</font></h2></center>
<?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","bbbn");
mysql_select_db("iasb_ims");
$res = mysql_query("select Event_id, Event_Type, Date_Event, Time_Event, Location, Desc_Event, Corrective_Action_Taken from client_report");
//$res = mysql_query("select Event_Type, age, area from table1 where age>20");
$prg->mysql_resource = $res;
//$prg->title = "Test Table";
$prg->generateReport();
?>
</body>
</html>
Thanking you,