PHP Classes

File: Sample1.php

Recommend this page to a friend!
  Classes of Cesar Alpendre   Print Line Table   Sample1.php   Download  
File: Sample1.php
Role: Example script
Content type: text/plain
Description: Sample 1
Class: Print Line Table
Generate an HTML table report from array of data
Author: By
Last change:
Date: 20 years ago
Size: 2,601 bytes
 

Contents

Class file image Download
<?php

/**=======================================================================//
// Example 1: 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 (
$cid) {
   
$rows = 0;
   
$prt = new PrintLineTable("Customers Report");
   
$result = SelectAllCustomer($cid,$database,$rows);
    if (
$rows > 0) {
        while (
$column = mysql_fetch_assoc($result)) {
           
$row = array("Customer ID" => $column["customer_number"],
                        
"Name" => $column["customer_name"],
                        
"Create Date" => $column["customer_create_date"],
                        
"Company Name" => $column["customer_company_name"],
                        
"Contract Number" => $column["customer_support_contract_number"],
                        
"Area Code" => $column["customer_area_code"],
                        
"Phone Number" => $column["customer_phone_number"],
                        );
           
$field_select = array("customer_number" => $column["customer_number"]);
           
$prt->PrintLine($row,$field_select,"update_customer.php"); // print line with href link
            # $prt->PrintLine($row); // print line without href link
       
}
       
$prt->PrintLineClose();
    }
    else {
       print
"<HR>\n";
       print
"</p><p><b><font size='4' color='#FF0000'>There aren't any customer record</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>";


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 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 */

?>