Free web development scripts for the webmasterDevelopment Scripts


 social media marketing services
 Site Navigation
Clicky Web Analytics
 o Development Scripts
 o Text Only Edition
 o PHP.net News
 o Tutorials
 o Register an account
 o New entries this week
 o Affiliates/Links
 o Contact Us
 o About us
 o Advanced Search

 Browse Path
 o 1 user online
 o Most users online: 67
 o Home
  o PHP
   o Databases
    o Script

 Member Login
User Name
Password

 Standards
Valid XHTML 1.0!
Valid 
CSS!

 Recommended Links
 o PHP Freaks
 o Paper Free Invoicing
 o Tutorials
 o Expired Domain Crawler

PM Report (Rated 0)

Description:

PM Report is a PHP/MySQL report generator. It creates customizable reports and is very simple to setup and use. You can select which database, table, and individual fields to use on your report. You can also select which field you would like to sort by and whether or not you would like a total for each column.

Code starts here


*** index.html ***

<?
session_start
();
if(
$clear == "yes") {session_destroy();}
?>
<html>
<head>
<title>PM Report ( http://www.busmgtsys.com )</title>
<link rel=stylesheet type=text/css href=css/dolphin.css>
</head>
<body>
<div align=center>
<form action="<? print $PHP_SELF; ?>" method="post">
<br>
<input type="hidden" name="clear" value="yes">
<input type="submit" value="Reset Database Information">
</form>
<?
if(isset($SQL_SERVER)){$_SESSION[SQL_SERVER] = $SQL_SERVER;}
if(isset(
$SQL_USER)){$_SESSION[SQL_USER] = $SQL_USER;}
if(isset(
$SQL_PASSWORD)){$_SESSION[SQL_PASSWORD] = $SQL_PASSWORD;}
if(isset(
$SQL_DATABASE)){$_SESSION[SQL_DATABASE] = $SQL_DATABASE;}
if(isset(
$SQL_TABLE)){$_SESSION[SQL_TABLE] = $SQL_TABLE;}


if(
$_SESSION[SQL_SERVER] == "" OR $_SESSION[SQL_USER] == "" OR $_SESSION[SQL_PASSWORD] == "") {
?>
<table>
<form action="<? print $PHP_SELF; ?>" method="post">
<tr>
<td align=right><b>MySQL Server Name:</b></td>
<td><input type="text" name="SQL_SERVER"></td>
</tr>
<tr>
<td align=right><b>MySQL User Name:</b></td>
<td><input type="text" name="SQL_USER"></td>
</tr>
<tr>
<td align=right><b>MySQL Password:</b></td>
<td><input type="text" name="SQL_PASSWORD"></td>
</tr>
<tr>
<td colspan=2 align=center>
<input type="submit" value="Submit">
<p>
<a href="http://www.busmgtsys.com">Visit the BMS website for updates!<br>www.busmgtsys.com</a>
</td>
</tr>
</form>
</table>
<?
exit;
} else {
$connection = mysql_connect("$SQL_SERVER","$SQL_USER","$SQL_PASSWORD") or die ("Unable to connect to MySQL server.");
}

if(
$_SESSION[SQL_DATABASE] == "") {
?>
<table>
<form action="<? print $PHP_SELF; ?>" method="post">
<tr>
<td align=right><b>MySQL Database:</b></td>
<td><input type="text" name="SQL_DATABASE"></td>
</tr>
<tr>
<td colspan=2 align=center>
<input type="submit" value="Submit">
<p>
<a href="http://www.busmgtsys.com">Visit the BMS website for updates!<br>www.busmgtsys.com</a>
</td>
</tr>
</form>
</table>
<?
exit;
} else {
$db = mysql_select_db("$_SESSION[SQL_DATABASE]") or die ("Unable to select requested database.");
}

if(
$_SESSION[SQL_TABLE] == "") {
?>
<table>
<form action="<? print $PHP_SELF; ?>" method="post">
<tr>
<td align=right><b>Database Table:</b></td>
<td>
<select type="text" name="SQL_TABLE">
<?
$result
= mysql_list_tables($_SESSION[SQL_DATABASE]);
if (!
$result) {
print
"DB Error, could not list tables\n";
print
'MySQL Error: ' . mysql_error();
exit;
}

while (
$row = mysql_fetch_row($result)) {
print
"<option value=\"$row[0]\">$row[0]</option>";
}

mysql_free_result($result);
?>
</select>
</td>
</tr>
<tr>
<td colspan=2 align=center>
<input type="submit" value="Submit">
<p>
<a href="http://www.busmgtsys.com">Visit the BMS website for updates!<br>www.busmgtsys.com</a>
</td>
</tr>
</form>
</table>
<?
exit;
}
?>
<table border=0 cellspacing=0 cellpadding=3>
<form action="generate.php" target="_blank" method="post">
<tr style="background:<? print $header_row_bg_color; ?>;color:<? print $header_row_fg_color; ?>;">
<td align=center valign=bottom><b> &nbsp Field &nbsp </b></td>
<td align=center valign=bottom><b> &nbsp Operator &nbsp </b></td>
<td align=center valign=bottom><b> &nbsp Value &nbsp <br> &nbsp ('%%' = wildcard) &nbsp </b></td>
<td align=center valign=bottom><b> &nbsp Number &nbsp <br> &nbsp Format &nbsp </b></td>
<td align=center valign=bottom><b> &nbsp Total &nbsp </b></td>
</tr>
<?
$fields
= mysql_list_fields("$_SESSION[SQL_DATABASE]", "$_SESSION[SQL_TABLE]", $connection);
$columns = mysql_num_fields($fields);
for (
$i = 0; $i < $columns; $i++) {
$field_name = mysql_field_name($fields, $i);
if(
$color == 0) {$alt_color = $alt_1_row_bg_color;$color = 1;} else {$alt_color = $alt_2_row_bg_color;$color = 0;}

print (
"<tr style=\"background:$alt_color;\">
<td>
<input type=\"checkbox\" name=\"field_number
$i\" value=\"$field_name\"> &nbsp <b>$field_name</b>
</td>
<td>
<select name=\"search_type
$i\">
<option value=\"LIKE\">LIKE</option>
<option value=\"NOT LIKE\">NOT LIKE</option>
<option value=\"=\">=</option>
<option value=\"!=\">!=</option>
<option value=\"<\"><</option>
<option value=\">\">></option>
<option value=\"<=\"><=</option>
<option value=\">=\">>=</option>
</select>
</td>
<td>
<input type=\"text\" name=\"search_value
$i\" value=\"%%\">
</td>
<td align=center>
<input type=\"checkbox\" name=\"number_format
$i\">
</td>
<td align=center>
<input type=\"checkbox\" name=\"total_col
$i\">
</td>
</tr>"
);
}
?>
<tr>
<td align=right><b>Sort By: &nbsp</b></td>
<td>
<select name="sort_by">
<?
$fields
= mysql_list_fields("$_SESSION[SQL_DATABASE]", "$_SESSION[SQL_TABLE]", $connection);
$columns = mysql_num_fields($fields);
for (
$i = 0; $i < $columns; $i++) {
$field_name = mysql_field_name($fields, $i);
print (
"<option value=\"$field_name\">$field_name</option>");
}
?>
</select>
</td>
<td>
<select name="order_by">
<option value="ASC">ASC</option>
<option value="DESC">DESC</option>
</select>
</td>
</tr>
<tr>
<td align=right><b>Any Totals?: &nbsp</b></td>
<td colspan=4><input type="radio" name="any_totals" value="no" CHECKED><b>NO</b> &nbsp <input type="radio" name="any_totals" value="yes"><b>YES</b></td>
</tr>
<tr>
<td colspan=5 align=center>
&nbsp
</td>
<tr>
<td colspan=5 align=center>
<input type=hidden name="SQL_SERVER" value="<? print $_SESSION[SQL_SERVER]; ?>">
<input type=hidden name="SQL_USER" value="<? print $_SESSION[SQL_USER]; ?>">
<input type=hidden name="SQL_PASSWORD" value="<? print $_SESSION[SQL_PASSWORD]; ?>">
<input type=hidden name="SQL_DATABASE" value="<? print $_SESSION[SQL_DATABASE]; ?>">
<input type=hidden name="SQL_TABLE" value="<? print $_SESSION[SQL_TABLE]; ?>">
<input type="submit" value="Generate Report">
<p>
<a href="http://www.busmgtsys.com">Visit the BMS website for updates!<br>www.busmgtsys.com</a>
</td>
</tr>
</form>
</table>
</div>
</body>
</html>



*** generator.php ***

<?
session_start
();
?>
<html>
<head>
<title>PM Report ( http://www.busmgtsys.com )</title>
<link rel=stylesheet type=text/css href=css/dolphin.css>
<!--
<script>
window.print();
</script>
-->
</head>
<body>
<div align="center">
<?
$connection
= mysql_connect("$SQL_SERVER","$SQL_USER","$SQL_PASSWORD") or die ("Unable to connect to MySQL server.");
$db = mysql_select_db("$SQL_DATABASE") or die ("Unable to select requested database.");

$num = 0;
$fields = mysql_list_fields("$SQL_DATABASE", "$SQL_TABLE", $connection);
$columns = mysql_num_fields($fields);

$file = fopen('EXPORT_REPORT.csv', 'w'); // erase textdata.txt if itexists!!
$fp = fopen("EXPORT_REPORT.csv", "a+");

for (
$i = 0; $i < $columns; $i++) {
if(${
"field_number".$i} != ""){
$num = $num+1;
${
"field_".$num} = mysql_field_name($fields, $i);
${
"search_type_".$num} = ${"search_type".$i};
${
"search_value_".$num} = ${"search_value".$i};

$svtext = "search_value_";

$fields_info = ($fields_info."&field_number".$i."=".${"field_".$num}."&search_type".$i."=".${"search_type_".$num}."&search_value".$i."=".${$svtext.$num});

if(
$num == 1) {
$search_query = ${"field_".$num}." ".${"search_type_".$num}." '${$svtext.$num}'";
} else {
$search_query = $search_query." AND ".${"field_".$num}." ".${"search_type_".$num}." '${$svtext.$num}'";
}
}
}

if(
$per_page == "") {$per_page = 10000;}
if(
$limit == "") {$limit = 0;}

if(
$search_query == "") {
print
"<br><big><b>No Search Criteria Was Selected!</b></big>";
} else {
$sql = mysql_query("SELECT * FROM $SQL_TABLE WHERE $search_query ORDER BY $sort_by $order_by LIMIT $limit,$per_page");

print (
"<table border=0 cellspacing=0 cellpadding=3>
<tr style=\"background:
$header_row_bg_color;color: $header_row_fg_color;\">");
$num = 0;
for (
$i = 0; $i < $columns; $i++) {
if(${
"field_number".$i} != ""){
$num = $num+1;
${
"field_".$num} = mysql_field_name($fields, $i);
$ftext = "field_";
$field_name = ${$ftext.$num};
$field_description = explode("_",$field_name);
$field_description1 = ucfirst($field_description[0]);
$field_description2 = ucfirst($field_description[1]);
$field_description3 = ucfirst($field_description[2]);
$field_description4 = ucfirst($field_description[3]);
$field_description5 = ucfirst($field_description[4]);
$field_description6 = ucfirst($field_description[5]);
$field_description7 = ucfirst($field_description[6]);
$field_description8 = ucfirst($field_description[7]);
$field_description9 = ucfirst($field_description[8]);
$field_description10 = ucfirst($field_description[9]);
print (
"<td valign=top align=center style=\"border-left:solid 1px #666666;border-right:solid 1px #666666;\"><b>$field_description1 $field_description2 $field_description3 $field_description4 $field_description5 $field_description6 $field_description7 $field_description8 $field_description9 $field_description10</b></td>");
if(
$num == "1") {$column_headings = $field_name;} else {$column_headings = $column_headings.",".$field_name;}
}
}

fwrite($fp,""."$column_headings\n");

print (
"</tr>");

$color = 0;

while (
$row = mysql_fetch_array($sql)) {
if(
$color == 0) {$alt_color = $alt_1_row_bg_color;$color = 1;} else {$alt_color = $alt_2_row_bg_color;$color = 0;}

print (
"<tr style=\"background:$alt_color;\">");

$num = 0;
for (
$i = 0; $i < $columns; $i++) {
if(${
"field_number".$i} != ""){
$num = $num+1;
${
"field_".$num} = mysql_field_name($fields, $i);
$ftext = "field_";
$row_id = ${$ftext.$num};

if(${
"number_format".$i} == ""){
$cell_data = $row[$row_id];
$cell_data_tot = $row[$row_id];
$c_align = "left";
} else {
$cell_data = number_format($row[$row_id],2);
$cell_data_tot = $row[$row_id];
$c_align = "right";
}
if(${
"total_col".$i} != ""){${$row_id."_total"} = ${$row_id."_total"}+$cell_data_tot;}

print (
"<td valign=top align=$c_align style=\"border-left:solid 1px #666666;border-right:solid 1px #666666;\"><b>$cell_data &nbsp</b></td>");
if(
$num == "1") {$column_data = $cell_data;} else {$column_data = $column_data.",".$cell_data;}
}
}

fwrite($fp,""."$column_data\n");

print (
"</tr>");
}

if(
$any_totals == "yes") {
print (
"<tr><td style=\"border:solid 2px #666666;background:#000066;color:#FFFFFF;\" colspan=$columns align=center><b> &nbsp TOTALS &nbsp </b></td></tr>");

print (
"<tr>");

$num = 0;
for (
$i = 0; $i < $columns; $i++) {
if(${
"field_number".$i} != ""){
$num = $num+1;
${
"field_".$num} = mysql_field_name($fields, $i);
$ftext = "field_";
$row_id = ${$ftext.$num};

if(${
"number_format".$i} == ""){
$c_align = "left";
$col_total = ${$row_id."_total"};
} else {
$c_align = "right";
$col_total = number_format(${$row_id."_total"},2);
}

print (
"<td valign=top align=$c_align style=\"border-left:solid 1px #666666;border-right:solid 1px #666666;\"><b>$col_total &nbsp</b></td>");
if(
$num == "1") {$column_data = $col_total;} else {$column_data = $column_data.",".$col_total;}
}
}
}

print (
"<tr><td style=\"border-top:solid 2px #666666\" colspan=$columns align=center><b> &nbsp End Of Page &nbsp </b></td></tr>");
?>
</table>
<?
fclose
($fp);
}
?>
<p>
<a href="EXPORT_REPORT.csv">Export Data</a>
<br>
( Right click on "Export Data" and select "Save Target As..." to save the file to your computer. )
<p>
<a href="javascript:void(window.close())">Close Window</a>
<p>
<a href="http://www.busmgtsys.com">Visit the BMS website for updates!<br>www.busmgtsys.com</a>
</div>
</body>
</html>


Submitted by zekebms on 12-01-2005 21:46


Recent Additions (from all categories)

(PHP) T Shirt Printing Software

(PHP) Youtube Video Organizer Script

(PHP) MP3z - MP3 Search Engine Script

(PHP) Recipez- PHP Recipe Script

(ASP) Stop image hotlinking and downloading. Web image protection is easy with Image Trapper.

Top Rated Scripts

(Javascripts) Javascript Delayed Redirection Rating: 5

(PHP) Random Links and images with PHP & MySQL Rating: 5

(PHP) RSS/XML news feed headline grabber! Rating: 5

(PHP) Random Signatures/Avatars Rating: 5

(Javascripts) Detecting Client Web Browser Rating: 5

© Copyright 2003 - Devscripts.net  Web Analytics