Login   Register  
PHP Classes
elePHPant
Icontem

File: test_database_table.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Manuel Lemos  >  Query result table display class  >  test_database_table.php  >  Download  
File: test_database_table.php
Role: Example script
Content type: text/plain
Description: Example script that shows how to use the class
Class: Query result table display class
Outputs tables with the result of database queries
Author: By
Last change: Removed argument passing by reference.
Date: 2008-06-08 15:51
Size: 4,081 bytes
 

Contents

Class file image Download
<?php
/*
 * test_database_table.php
 *
 * @(#) $Header: /home/mlemos/cvsroot/PHPlibrary/test_database_table.php,v 1.4 2008/06/08 22:32:03 mlemos Exp $
 *
 */

?><html>
<head>
<title>Test for Manuel Lemos' database table class</title>
</head>
<body>
<h1><center>Test for Manuel Lemos' PHP database table class</center></h1>
<hr />
<?php

/*
 * Include Metabase package code.
 */
    
require("metabase/metabase_database.php");
    require(
"metabase/metabase_interface.php");

/*
 * Include table and database table class code.
 */
    
require("tableclass.php");
    require(
"databasetableclass.php");

/*
 * Define a subclass of the database table class to customise any output aspects.
 */
class my_database_table_class extends database_table_class
{
};

/*
 * Create a database table object.
 */
    
$database_table=new my_database_table_class;

/*
 * Setup database connection environment.
 */

    
require("database_setup.php");

    if(!
strcmp($error=MetabaseSetupDatabase($database_arguments$database_table->database),""))
    {

        
MetabaseSetDatabase($database_table->database,"currencies");

/*
 * Define table columns layout.
 */

            
$database_table->columns=array(
                array(
                    
"title"=>"ID",
                    
"columnname"=>"id",
                    
"type"=>"INTEGER"
                
),
                array(
                    
"title"=>"Symbol",
                    
"columnname"=>"currency",
                    
"type"=>"TEXT"
                
),
                array(
                    
"title"=>"World zone",
                    
"columnname"=>"zone",
                    
"type"=>"TEXT"
                
),
                array(
                    
"title"=>"Name",
                    
"columnname"=>"name",
                    
"type"=>"TEXT"
                
),
                array(
                    
"title"=>"Current value",
                    
"columnname"=>"current_value",
                    
"type"=>"DECIMAL"
                
)
            );

/*
 * Define table output parameters
 */

        
$database_table->page=0;
        
$database_table->rowsperpage=5;
        
$database_table->border=0;
        
$database_table->headersrowbackgroundcolor="#CCCCCC";
        
$database_table->oddrowsbackgroundcolor="#EEEE00";
        
$database_table->evenrowsbackgroundcolor="#CCCC00";
        
$database_table->highlightrowcolor="#00CCCC";
        
$database_table->listpages=3;
        
$database_table->firstprefix="<< First";
        
$database_table->previousprefix="< Previous";
        
$database_table->nextsuffix="Next >";
        
$database_table->lastsuffix="Last >>";
        
$database_table->rangeinfirstlast=0;
        
$database_table->rangeinpreviousnext=0;

/*
 * Adjust table display parameters according to CGI option values
 */
        
if(IsSet($_REQUEST['page'])
        && !
strcmp($_REQUEST['page'],strval(intval($_REQUEST['page'])))
        && 
intval($_REQUEST['page'])>=0)
            
$database_table->page=intval($_REQUEST['page']);
        if(IsSet(
$_REQUEST['rowsperpage'])
        && !
strcmp($_REQUEST['rowsperpage'],strval(intval($_REQUEST['rowsperpage'])))
        && 
intval($_REQUEST['rowsperpage'])>=0
        
&& intval($_REQUEST['rowsperpage'])<=100)
            
$database_table->rowsperpage=intval($_REQUEST['rowsperpage']);
        
$database_table->pagelinkvalues=array(
            
"rowsperpage"=>$database_table->rowsperpage
        
);

/*
 * Output the database query result table.
 */
        
if(strcmp($output=$database_table->outputquery("SELECT * FROM currencies","SELECT COUNT(*) FROM currencies"),""))
            echo 
$output;
        else
            
$error=$database_table->error;


/*
 * Output the database query result table using prepared query statements.
 *
 *    if(($select_statement=MetabasePrepareQuery($database_table->database,"SELECT * FROM currencies")))
 *    {
 *        if(($count_statement=MetabasePrepareQuery($database_table->database,"SELECT COUNT(*) FROM currencies")))
 *        {
 *
 *            // query arguments should be set here.
 *
 *            if(strcmp($output=$database_table->outputpreparedquery($select_statement,$count_statement),""))
 *                echo $output;
 *            else
 *                $error=$database_table->error;
 *            MetabaseFreePreparedQuery($database_table->database,$count_statement);
 *        }
 *        else
 *            $error=MetabaseError($database_table->database);
 *        MetabaseFreePreparedQuery($database_table->database,$select_statement);
 *    }
 *    else
 *        $error=MetabaseError($database_table->database);
 */

    
}

/*
 * Output error message in case something failed.
 */
    
if(strcmp($error,""))
        echo 
"<h2><center>Database error: $error.</center></h2>\n";
?>
<hr />
</body>
</html>