Login   Register  
PHP Classes
elePHPant
Icontem

File: Sample2.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Cesar Alpendre  >  Print Line Table  >  Sample2.php  >  Download  
File: Sample2.php
Role: Example script
Content type: text/plain
Description: Sample 2
Class: Print Line Table
Generate an HTML table report from array of data
Author: By
Last change:
Date: 9 years ago
Size: 6,964 bytes
 

Contents

Class file image Download
<?php

/**=======================================================================//
// Example 2: use of the functions of PrintLineTable
//========================================================================*/

include_once("../Genericos/PrintLineTable.inc.php");

$host "localhost";
$user "root";
$password "";
$database "customer";

$cid connect_database($host,$user,$password,$database);
if (isset(
$_REQUEST['submit'])) {
    
$customer_number $_REQUEST['customer_number'];
    if (
$customer_number == null) {
        
$prt = new PrintLineTable("Customers and Problems Report");
        
$result SelectAllCustomerAndProblem($cid,$database,$rows);
        if (
$rows 0) {
            
$until_column 2;
            while (
$column mysql_fetch_assoc($result)) {
                
$row = array("Customer ID" => $column["customer_number"],
                             
"Customer Name" => $column["customer_name"],
                             
"Problem Number" => $column["problem_number"],
                             
"Problem Open Datetime" => $column["problem_open_datetime"],
                             
"Problem Description" => $column["problem_description"],
                             
"Problem Status" => $column["problem_status"],
                             
"Problem Severity" => $column["problem_severity"],
                            );
                
$prt->PrintLineIndented($row,$until_column);
            }
            
$prt->PrintLineClose();
        }
        else {
           print 
"<p>&nbsp;";
           print 
"</p><p><b><font size='4' color='#FF0000'>There aren't any Customer record related to Problems</font></b></p>";
        }
    }
    else {
        
$customer_name SelectOneCustomerName($cid,$database,$rows,$customer_number);
        
$prt = new PrintLineTable("Problems Report for the Customer [".$customer_name."]");
        
$result SelectProblemByCustomer($cid,$database,$rows,$customer_number);
        if (
$rows 0) {
            while (
$column mysql_fetch_assoc($result)) {
                
$row = array("Problem Number" => $column["problem_number"],
                             
"Problem Open Datetime" => $column["problem_open_datetime"],
                             
"Problem Description" => $column["problem_description"],
                             
"Problem Status" => $column["problem_status"],
                             
"Problem Severity" => $column["problem_severity"],
                            );
                
$field_select = array("problem_number" => $column["problem_number"]);
                
$prt->PrintLine($row,$field_select,"Update_Problem.php"); // print line with href link
                #  $prt->PrintLine($row);                                 // print line without href link
            
}
            
$prt->PrintLineClose();
        }
        else {
            print 
"<p>&nbsp;";
            print 
"</p><p><b><font size='4' color='#FF0000'>There aren't any Customer record related to Problems</font></b></p>";
        }
    }
    
mysql_free_result($result);
    
connect_close($cid);
    print 
"<p align='center'><a href='index.htm' target='_parent'><img border='0' src='goback.gif' width='26' height='26'>Goback</a></td>";
}
elseif (isset(
$_REQUEST['cancel'])) {
    
connect_close($cid);
    print 
"<script language='JavaScript'>window.parent.location='index.htm';</script>";
}
else {
    
$prt = new PrintLineTable("Customers and Problems Report");
    print 
"<HR>\n";
    print 
"<TABLE border=0>\n";
    print 
"<tr><td><fieldset><legend><b>Selecione o Customer</b></legend><table border=0>\n";
    print 
"<form name='dados' method='POST' action=''>\n";
    print 
"<td align=right width='2'>\n";
    print 
"<select name='customer_number' size='1'><font face='Verdana, Arial, Helvetica, sans-serif'>\n";
    
$result SelectAllCustomer($cid,$database,$rows);
    if (
$rows 0) {
        print 
"<option value=''>All Customers</option>\n";
        while (
$column mysql_fetch_assoc($result)) {
               
$customer_number $column['customer_number'];
               
$customer_name $column['customer_name'];
               print 
"<option value='$customer_number'>$customer_name</option>\n";
        }
    }
    
mysql_free_result($result);
    print 
"</select></font></td>\n";
    print 
"</tr>\n";
    print 
"<tr>\n";
    print 
"<td width='50%'><p align='center'>";
    print 
"<input type='submit' value='        OK       ' name='submit'>&nbsp;&nbsp;&nbsp;";
    print 
"<input type='submit' value='      Cancel     ' name='cancel'>";
    print 
"</td></tr></table>";
    print 
"</form>";
    print 
"</table>";
    print 
"</body>";
}

function 
connect_database($host,$user,$password,$database) {  /* Construtor da conex„o do database */
    
$cid mysql_connect($host,$user,$password) or die("I could not do the connection with the database $database");
    if (!
$cid) {
        exit(
"Error in the connection with the database: "$database"Error:"mysql_error() . "\n");
    }
    
mysql_select_db($database$cid);
    return 
$cid;
}  
/* End of Function */

function connect_close($cid) {
    
mysql_close ($cid);
}  
/* End of Function */

function SelectAllCustomerAndProblem($cid,$database,&$rows) {
    
$query "SELECT *
                FROM customer cust, problem pro
               WHERE cust.customer_number = pro.customer_number
               ORDER BY cust.customer_name"
;
    
$result mysql_db_query($database,$query,$cid) or die ("Invalid query $query");
    
$rows   mysql_num_rows($result);
    return 
$result;
}   
/* End of Function */

function SelectProblemByCustomer($cid,$database,&$rows,$customer_number) {
    
$query "SELECT *
                FROM customer cust, problem pro
               WHERE cust.customer_number = 
$customer_number
                 AND cust.customer_number = pro.customer_number
               ORDER BY pro.problem_open_datetime DESC"
;
    
$result mysql_db_query($database,$query,$cid) or die ("Invalid query $query");
    
$rows   mysql_num_rows($result);
    return 
$result;
}   
/* End of Function */

function SelectAllCustomer($cid,$database,&$rows) {
    
$query "SELECT * FROM customer ORDER BY customer_name";
    
$result mysql_db_query($database,$query,$cid) or die ("Invalid query $query");
    
$rows   mysql_num_rows($result);
    return 
$result;
}   
/* End of Function */

function SelectOneCustomerName($cid,$database,&$rows,$customer_number) {
    
$query "SELECT customer_name FROM customer WHERE customer_number = $customer_number";
    
$result mysql_db_query($database,$query,$cid) or die ("Invalid query $query");
    
$rows   mysql_num_rows($result);
    if (
$rows 0) {
        
$column mysql_fetch_assoc($result);
        
mysql_free_result($result);
        return 
$column["customer_name"];
    }
    else {
        return 
null;
    }
}   
/* End of Function */

?>