Home arrow PHP arrow Page 4 - Building A Quick-And-Dirty Guestbook With patGuestbook (part 2)

Bringing In The Database - PHP

In this concluding article of our two-part series on rapid guestbook implementation with patGuestbook, find out how to tweak patGuestbook a litle more by controlling the viewable entries, customizing the user interface, and protecting access to the administration module.

TABLE OF CONTENTS:
  1. Building A Quick-And-Dirty Guestbook With patGuestbook (part 2)
  2. Adopting A Moderate Approach
  3. If Looks Could Kill...
  4. Bringing In The Database
  5. A Well-Formed Plan
  6. When Things Go Wrong
  7. Locking It Down
  8. Over And Out
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 76
March 11, 2003

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: