PHP
  Home arrow PHP arrow Page 4 - Building A Quick-And-Dirty Guestbook With patGuestbook (part 2)
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? 
Google.com  
PHP

Building A Quick-And-Dirty Guestbook With patGuestbook (part 2)
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 76
    2003-03-11


    Table of Contents:
  • Building A Quick-And-Dirty Guestbook With patGuestbook (part 2)
  • Adopting A Moderate Approach
  • If Looks Could Kill...
  • Bringing In The Database
  • A Well-Formed Plan
  • When Things Go Wrong
  • Locking It Down
  • Over And Out

  • 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


    Building A Quick-And-Dirty Guestbook With patGuestbook (part 2) - Bringing In The Database
    ( Page 4 of 8 )

    At this point, I have identified the layout for the pages, and also shown you the menu that will be displayed on each page. Now for the most important item - connecting all this up to the patGuestbook database.

    Here's the code:

    <table border="0" cellpadding="0" cellspacing="0"> <tr> <td class="textinvert" colspan="3"> Welcome to {GB_NAME}!<br><br> </td> </tr> </table> <pattemplate:tmpl name="entry"> <pattemplate:tmpl name="displayName" visibility="hidden" varscope="entry" type="simpleCondition" requiredVars="ENTRY_NAME"> <table width="550" cellpadding="0" cellspacing="1" border="0"> <tr> <td> <table width="100%" cellpadding="6" cellspacing="0" border="0"> <tr> <td class="head" >By <b>{ENTRY_NAME}</b> on {ENTRY_DATE}</td> </tr> </table> </td> </tr> </pattemplate:tmpl> <tr> <td class="text"> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td> <br> <table border="0" cellpadding="0" cellspacing="2"> <pattemplate:tmpl name="displayEmail" visibility="hidden" varscope="entry" type="simpleCondition" requiredVars="ENTRY_EMAIL"> <tr valign="top"> <td class="text" nowrap><b>{LABEL_EMAIL}</b></td> <td class="text"> : </td> <td class="text"><a href="mailto:{ENTRY_EMAIL}">{ENTRY_EMAIL}</a></td> </tr> </pattemplate:tmpl> <pattemplate:tmpl name="displayHomepage" visibility="hidden" varscope="entry" type="simpleCondition" requiredVars="ENTRY_HOMEPAGE"> <tr valign="top"> <td class="text" nowrap><b>{LABEL_HOMEPAGE}</b></td> <td class="text"> : </td> <td class="text"><a href="{ENTRY_HOMEPAGE}" target="_blank">{ENTRY_HOMEPAGE}</a></td> </tr> </pattemplate:tmpl> <pattemplate:tmpl name="displayEntry" visibility="hidden" varscope="entry" type="simpleCondition" requiredVars="ENTRY_ENTRY"> <tr> <td colspan="3"><img src="skins/melonfire/img/px.gif" width="1" height="5" alt="" border="0"></td> </tr> <tr valign="top"> <td class="text" nowrap><b>{LABEL_ENTRY}</b></td> <td class="text"> : </td> <td class="text">{ENTRY_ENTRY}</td> </tr> </pattemplate:tmpl> <pattemplate:tmpl name="ratings" visibility="hidden"> <tr> <td colspan="3"><img src="skins/melonfire/img/px.gif" width="1" height="5" alt="" border="0"></td> </tr> <tr valign="top"> <td class="text" colspan="3"><b>Ratings</b></td> </tr> <pattemplate:tmpl name="ratingEntry"> <tr valign="top"> <td class="text" nowrap><b> · {RATING_LABEL}</b></td> <td class="text"> : </td> <td class="text">{RATING_VALUE}</td> </tr> </pattemplate:tmpl> </pattemplate:tmpl> </table> <img src="skins/melonfire/img/px.gif" width="1" height="5" alt="" border="0"><br> </td> </tr> </table> </td> </tr> </table> <img src="skins/melonfire/img/px.gif" width="1" height="20" alt="" border="0"><br> </pattemplate:tmpl> <table width="550" cellpadding="1" cellspacing="0" border="0"> <tr> <td> <table width="100%" cellpadding="3" cellspacing="0" border="0"> <tr> <pattemplate:tmpl name="previouspage" type="condition" conditionvar="URL_PREVIOUSPAGE"> <patTemplate:sub condition="default"> <td class="text" nowrap width="33%"> <a href="{URL_PREVIOUSPAGE}" style="text-decoration:none"><< previous page</a> <br> </td> </patTemplate:sub> <patTemplate:sub condition="empty"> <td width="33%"><img src="skins/melonfire/img/px.gif" width="1" height="1" alt="" border="0"></td> </patTemplate:sub> </pattemplate:tmpl> <td align="center" class="text" width="33%"><a href="{URL_ADDENTRY}" style="text-decoration:none">add entry</a></td> <pattemplate:tmpl name="nextpage" type="condition" conditionvar="URL_NEXTPAGE"> <patTemplate:sub condition="default"> <td class="text" align="right" nowrap width="33%"> <a href="{URL_NEXTPAGE}" style="text-decoration:none" >next page >></a> <br> </td> </patTemplate:sub> <patTemplate:sub condition="empty"> <td width="33%"><img src="skins/melonfire/img/px.gif" width="1" height="1" alt="" border="0"></td> </patTemplate:sub> </pattemplate:tmpl> </tr> </table> </td> </tr> </table>
    Chaos, you're thinking...and rightly so. But let me help make some sense of it.

    1. First, the page header, displaying the name of the guestbook.

    <tr> <td class="textinvert" colspan="3"> Welcome to {GB_NAME}!<br><br> </td> </tr>
    {GB_NAME} is a special patGuestbook template variable that will be replaced by the name of the guestbook specified at run time - in this example, "Voice of the People".

    2. Next, I have to define the template used for display of each field in the guestbook. In this example, I would like to display the name of the user along with the time at which the entry was saved.

    <pattemplate:tmpl name="displayName" visibility="hidden" varscope="entry" type="simpleCondition" requiredVars="ENTRY_NAME"> <table width="550" cellpadding="0" cellspacing="1" border="0"> <tr> <td> <table width="100%" cellpadding="6" cellspacing="0" border="0"> <tr> <td class="head" >By <b>{ENTRY_NAME}</b> on {ENTRY_DATE}</td> </tr> </table> </td> </tr> </pattemplate:tmpl>
    Once I am done with the user's name via the {ENTRY_NAME} and {ENTRY_DATE} variables, I can proceed to the user's email address and URL.

    <pattemplate:tmpl name="displayEmail" visibility="hidden" varscope="entry" type="simpleCondition" requiredVars="ENTRY_EMAIL"> <tr valign="top"> <td class="text" nowrap><b>{LABEL_EMAIL}</b></td> <td class="text"> : </td> <td class="text"><a href="mailto:{ENTRY_EMAIL}">{ENTRY_EMAIL}</a></td> </tr> </pattemplate:tmpl> <pattemplate:tmpl name="displayHomepage" visibility="hidden" varscope="entry" type="simpleCondition" requiredVars="ENTRY_HOMEPAGE"> <tr valign="top"> <td class="text" nowrap><b>{LABEL_HOMEPAGE}</b></td> <td class="text"> : </td> <td class="text"><a href="{ENTRY_HOMEPAGE}" target="_blank">{ENTRY_HOMEPAGE}</a></td> </tr> </pattemplate:tmpl>
    Once again, two special patGuestbook variables -{ENTRY_EMAIL} and {ENTRY_HOMEPAGE} - are used to retrieve the information entered by the user. I can also display the appropriate labels for each field via the {LABEL_EMAIL} and {LABEL_HOMEPAGE} variables.

    How about displaying the heart of the guestbook - the user's comments?

    <pattemplate:tmpl name="displayEntry" visibility="hidden" varscope="entry" type="simpleCondition" requiredVars="ENTRY_ENTRY"> <tr> <td colspan="3"><img src="skins/melonfire/img/px.gif" width="1" height="5" alt="" border="0"></td> </tr> <tr valign="top"> <td class="text" nowrap><b>{LABEL_ENTRY}</b></td> <td class="text"> : </td> <td class="text">{ENTRY_ENTRY}</td> </tr> </pattemplate:tmpl>
    Finally, the rating field, which is also fairly straightforward.

    <pattemplate:tmpl name="ratings" visibility="hidden"> <tr> <td colspan="3"><img src="skins/melonfire/img/px.gif" width="1" height="5" alt="" border="0"></td> </tr> <tr valign="top"> <td class="text" colspan="3"><b>Ratings</b></td> </tr> <pattemplate:tmpl name="ratingEntry"> <tr valign="top"> <td class="text" nowrap><b> · {RATING_LABEL}</b></td> <td class="text"> : </td> <td class="text">{RATING_VALUE}</td> </tr> </pattemplate:tmpl> </pattemplate:tmpl>
    One of the configuration variables in the guestbook is the number of entries to be displayed on a single page. So, I also need to add paging logic, and a link to add new entries to the system.

    <table width="550" cellpadding="1" cellspacing="0" border="0"> <tr> <td> <table width="100%" cellpadding="3" cellspacing="0" border="0"> <tr> <pattemplate:tmpl name="previouspage" type="condition" conditionvar="URL_PREVIOUSPAGE"> <patTemplate:sub condition="default"> <td class="text" nowrap width="33%"> <a href="{URL_PREVIOUSPAGE}" style="text-decoration:none"><< previous page</a> <br> </td> </patTemplate:sub> <patTemplate:sub condition="empty"> <td width="33%"><img src="skins/melonfire/img/px.gif" width="1" height="1" alt="" border="0"></td> </patTemplate:sub> </pattemplate:tmpl> <td align="center" class="text" width="33%"><a href="{URL_ADDENTRY}" style="text-decoration:none">add entry</a></td> <pattemplate:tmpl name="nextpage" type="condition" conditionvar="URL_NEXTPAGE"> <patTemplate:sub condition="default"> <td class="text" align="right" nowrap width="33%"> <a href="{URL_NEXTPAGE}" style="text-decoration:none" >next page >></a> <br> </td> </patTemplate:sub> <patTemplate:sub condition="empty"> <td width="33%"><img src="skins/melonfire/img/px.gif" width="1" height="1" alt="" border="0"></td> </patTemplate:sub> </pattemplate:tmpl> </tr> </table> </td> </tr> </table>
    The {URL_PREVIOUSPAGE} and {URL_NEXTPAGE} variables are used to display the links to the previous and next page, if required. the {URL_ADDENTRY} variable contains the URL that allows users to add a new entry to the guestbook.

     
     
    >>> More PHP Articles          >>> More By Harish Kamath, (c) Melonfire
     

       

    PHP ARTICLES

    - Adding Ordering and Grouping Clauses to the ...
    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - 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...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek