PHP
  Home arrow PHP arrow Page 4 - PHP Fast Template
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

PHP Fast Template
By: Ian Felton
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 18
    2001-07-02


    Table of Contents:
  • PHP Fast Template
  • Assigning templates to objects
  • Assigning variables to FastTemplate objects
  • MySQL Data parsed through FastTemplates
  • Multiple templates: Rows of data into a table
  • Summary

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    PHP Fast Template - MySQL Data parsed through FastTemplates
    ( Page 4 of 6 )

    Using the above information as a guide, look at this code that works on data taken from a MySQL database and parses it through HTML templates.

    <?php //getData.php include "class.FastTemplate.php3"; //instantiate a new FastTemplate instance $tpl = new FastTemplate("../templates"); //associate an HTML template to a variable $tpl->define(array( "toplevel" => "phone_numbers.tpl" )); //Connect to database mysql_connect (localhost, root, passwd); //select database to use mysql_select_db (testDB); //select data from MySQL database for example code $GetData = mysql_query ("select Phone from Business where Name = '$Name'"); //Get array results $GetDataArray = mysql_fetch_array($GetData); //Associate contents of hash array with variable $Phone = $GetDataArray["Phone"]; //assign $Phone to FastTemplate instance $tpl->assign("PHONE", $Phone); //pass the data to the HTML template $tpl->parse(MAIN, "toplevel"); $tpl->FastPrint(); ?>
    From here, the phone number data taken from the database will be passed to the HTML template, "phone_numbers.tpl". Here are the contents of phone_numbers.tpl :

    <HTML> <BODY> <P> Here is the phone number you wanted: {PHONE} </P> </BODY> </HTML>
    On the web page it will look like this:

    Here is the phone number you wanted: 555-5555




     
     
    >>> More PHP Articles          >>> More By Ian Felton
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT