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 custom fields + 
add, update and delete

Tutorials

>

Tutorial Database

>

Tutorial : Table loaded by a query with custom fields + add, update and delete


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

Tutorial : Table loaded by a query with custom fields + add, update and delete:

name
url_link
 
 
 
 
WebSite-PHP
Edit: http://www.website-php.com
Meteo Europ
Edit: http://www.meteo-europ.com


Go back to tutorial of the componant Database



Source code

Source code


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

<?php
class Database07 extends Page {
    public function 
InitializeComponent() {
        
parent::$PAGE_TITLE "Tutorial : Table loaded 
                by a query with custom fields + 
                add, update and delete"
;
        
        
// Create table
        
$this->render = new Table();
        
$this->render->setId("user_table_7");
        
$this->render->activateAdvanceTable();
        
        
// Define table properties (display, update, ...)
        
$properties = array(
            
FavoritePageDbTable::FIELD_NAME => array(
                
"width" => 80,
                
"update" => false
            
),
            
"url_link" => array(
                
// link url_link with real table column url
                
"db_attribute" => FavoritePageDbTable::FIELD_URL,
                
"strip_tags" => true // no tag allowed
            
),
            
            
// To insert, update or delete URL you need to add the 
            // attribute, but you can hide it.
            // These fields will not appear: "display" => false
            
FavoritePageDbTable::FIELD_URL => array(
                
"display" => false
            
)
        );
        
        
// load data from query
        
$sql = new SqlDataView(new FavoritePageDbTable());
        
        
// Specify custom fields (create column url_link clickable)
        
$sql->setCustomFields(
            
FavoritePageDbTable::FIELD_NAME,
            
"concat('Edit: <a href=''', url, ''' target=''_blank''".
            
" rel=''nofollow''>', url, '</a>') as url_link",
            
FavoritePageDbTable::FIELD_URL);

        
// Filter on actif
        
$sql->setClause(UserDbTable::FIELD_ACTIF."=0 OR ".
                        
UserDbTable::FIELD_ACTIF." IS NULL");
                        
        
$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 `favorite_page`;

/*==============================================================*/
/* 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);


Share

 


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