Web Database Programming Week 6 - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Web Database Programming Week 6

Description:

Using Templates. Updating Web Database. PHP & HTML. PHP code can be inserted anywhere in HTML code ... PEAR Integrated Template. PEAR. PHP Extension and ... – PowerPoint PPT presentation

Number of Views:52
Avg rating:3.0/5.0
Slides: 14
Provided by: huaha
Learn more at: http://www.albany.edu
Category:

less

Transcript and Presenter's Notes

Title: Web Database Programming Week 6


1
Web Database Programming Week 6
  • Using Templates
  • Updating Web Database

2
PHP HTML
  • PHP code can be inserted anywhere in HTML code
  • PHP code can output any HTML code
  • Tightly mixed code (e.g. our sample code)
  • Hard to read
  • Hard to maintain
  • What if you want to change the appearance of the
    page?
  • What if you decide to use a different algorithm?

3
Separate Presentation and Processing
  • An important user interface design principle
  • Easy to change interface or backend processing
    independently
  • Easier maintenance
  • Reusable code
  • How?
  • Using templates

4
Template
  • Define HTML presentation
  • Placeholders
  • To be filled with data from PHP code
  • Extensions to PHP
  • Smarty
  • PEAR Integrated Template

5
PEAR
  • PHP Extension and Application Repository
  • Includes many packages
  • DB, HTML_Template_IT, Authentication, Encryption,
    Graphics, XML, SOAP
  • Core packages comes with PHP 4.3.0 later
  • Optional packages needs to be installed

6
HTML_Template_IT Template
  • http//pear.php.net/manual/en/package.html.html-te
    mplate-it.php
  • Template Format
  • Regular HTML
  • Placeholder
  • placeholder_name
  • Block
  • lt!-- BEGIN block_name --gt
  • lt!-- END block_name --gt

7
HTML_Template_IT Class
  • Use the class
  • require_once HTML/Template/IT.php
  • Create the object
  • template new HTML_Template_IT(template_dir)
  • Call the methods
  • template-gtloadTemplatefile(template_filename,
    true, true)
  • template-gtsetCurrentBlock(block_name)
  • template-gtsetVariable(placeholder_name, data)
  • template-gtparseCurrentBlock()
  • template-gtshow()

8
Update Database
  • Table Operations
  • Create table structure
  • Change table structure
  • Delete table
  • Record Operations
  • Insert a record to a table
  • Update a record
  • Delete a record

9
Making an Insert Form
  • Example
  • Notes
  • Recall that PHP will convert form field names
    into variables in the action page
  • use input typehidden to set predefined and
    previously fixed values (like foreign keys) and
    to carry values forward

10
Using SQL for Insert
  • SQL
  • INSERT INTO tablename (columnnames)
  • VALUES (values)
  • Note
  • value do not have to come from form they could,
    for example, be computed, or taken from another
    query
  • Remember single quote for text values and not
    for numbers

11
An Update Form
  • Example
  • Notes
  • note the addition of a record ID value (which we
    must get from somewhere!) tells us which record
    we are updating.

12
Using SQL for Update
  • SQL
  • UPDATE tablename
  • SET columnname value, ...
  • WHERE condition
  • Notes
  • value are set on all records matching the
    condition!

13
Deleting data from a table
  • The form for the SQL part of the code is
  • DELETE FROM tablename
  • WHERE condition
  • Note
  • all records matching the condition are deleted
  • if there is no where clause deletes all records
    in table
Write a Comment
User Comments (0)
About PowerShow.com