WebSite-PHP Framework PHP
Multi language
Simple Ajax mode
No HTML, no JavaScript
URL rewriting
Mail sending
Sitemap - RSS - Web service
Download WebSite-PHP FrameWork now
 


Loading
 


Tutorial : Table loaded 
by a query with features add, update, delete 
and foreign key

Tutorials

>

Tutorial Database

>

Tutorial : Table loaded by a query with features add, update, delete and foreign key


Database-06: Tutorial of the composant Database of the PHP FrameWork WebSite-PHP.

Tutorial : Table loaded by a query with features add, update, delete and foreign key:

Id Name Birthday Sex Page Actif  
 
 
 
 
 
 
 
 


Go back to tutorial of the componant Database



Source code

Source code


File: /pages/tutorials/database/database-06.php

<?php
class Database06 extends Page {
    public function 
InitializeComponent() {
        
parent::$PAGE_TITLE "Tutorial : Table loaded 
                by a query with features add, update, delete 
                and foreign key"
;
        
        
// Create table
        
$this->render = new Table();
        
$this->render->setId("user_table_6");
        
$this->render->activateAdvanceTable();
        
        
// Defined header
        
$header $this->render->addRowColumns(
                            
"Id""Name",
                            
"Birthday",
                            
"Sex""Page",
                            
"Actif"
                        
);
        
$header->setHeaderClass(0);
        
        
// Define table properties (width, align, ...)
        // You need to configure foreign key to display
        // the foreign key value (and not the id)
        
$properties = array(
            
UserDbTable::FIELD_NAME => array(
                
"width" => 80,
                
"strip_tags" => true,
                
"allowable_tags" => "<b><i>"
            
),
            
UserDbTable::FIELD_BIRTHDAY => array(
                
"width" => 80
            
),
            
UserDbTable::FIELD_SEX_ID => array(
                
"fk_attribute" => SexDbTable::FIELD_VALUE,
                
"width" => 70,
                
"align" => RowTable::ALIGN_LEFT
            
),
            
UserDbTable::FIELD_FAVORITE_PAGE_ID => array(
                
"fk_attribute" => FavoritePageDbTable::FIELD_NAME,
                
"fk_where" => UserDbTable::FIELD_ACTIF." = 1",
                
"fk_orderby" => UserDbTable::FIELD_NAME,
                
"width" => 120,
            )
        );
        
        
// Load data from query
        
$sql = new SqlDataView(new UserDbTable());
        
$this->render->loadFromSqlDataView($sql,
                            
$properties// Defined properties
                            
true// Insert activate
                            
true// Update activate
                            
true // Delete activate
                        
);
    }
    
    
// You need to add this method to trigger the table's events.
    // All kind of events (Insert, Update or Delete) are managed by
    // the method onChangeTableFromSqlDataView of the Table object.
    
public function onChangeTableFromSqlDataView($sender) {
        
$this->render->onChangeTableFromSqlDataView($sender);
    }
}
?>


Go back to tutorial of the componant Database


Tables

Tables


drop table if exists `user`;
drop table if exists `sex`;
drop table if exists `favorite_page`;

/*==============================================================*/
/* table: `user`                                                */
/*==============================================================*/
create table `user`
(
   user_id          int not null  auto_increment,
   name             varchar(50),
   birthday         date,
   sex_id           int,
   favorite_page_id int,
   actif            boolean,
   primary key (user_id)
) engine = innodb;

/*==============================================================*/
/* table: `sex`                                                 */
/*==============================================================*/
create table `sex`
(
   sex_id           int not null  auto_increment,
   value            varchar(20),
   primary key (sex_id)
) engine = innodb;

insert into `sex` (value) values('Man');
insert into `sex` (value) values('Woman');

/*==============================================================*/
/* table: `favorite_page`                                       */
/*==============================================================*/
create table `favorite_page`
(
   favorite_page_id  int not null  auto_increment,
   name              varchar(20),
   url               varchar(255),
   actif             boolean,
   primary key (favorite_page_id)
) engine = innodb;

insert into `favorite_page` (name, url, actif) 
    values('WebSite-PHP', 'http://www.website-php.com', true);
insert into `favorite_page` (name, url, actif) 
    values('Meteo Europ', 'http://www.meteo-europ.com', true);
insert into `favorite_page` (name, url, actif) 
    values('OracleRef', 'http://www.oracleref.com', true);
insert into `favorite_page` (name, url, actif) 
    values('WebSite-PHP', 'http://www.website-php.com', false);
insert into `favorite_page` (name, url, actif) 
    values('Meteo Europ', 'http://www.meteo-europ.com', false);
insert into `favorite_page` (name, url, actif) 
    values('OracleRef', 'http://www.oracleref.com', false);


alter table `user` add constraint fk_ref_user_sex 
            foreign key (sex_id)
      references `sex` (sex_id);

alter table `user` add constraint fk_ref_user_favorite 
            foreign key (favorite_page_id)
      references `favorite_page` (favorite_page_id);


Share

 


Copyright © 2009-2024 WebSite-PHP Framework PHP
Home Documentation Download Quick start Tutorials Wiki Issue Tracker