PHP
  Home arrow PHP arrow Page 4 - Building A Quick-And-Dirty Guestbook W...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
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

Building A Quick-And-Dirty Guestbook With patGuestbook (part 2)
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 63
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview
    - Handling Attachments in MIME Email with PHP
    - Completing the Project Management Application
    - Sending MIME Email with PHP
    - Handling Files for a Project Management Appl...
    - Viewing and Editing Tasks for a Project Mana...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway