Manila Bulletin Online
Nav Bar   Tue Jan 17,2006 Navigation Nav Bar
spacer
 
spacer
spacer
spacer
spacer
spacer
spacer



 
spacer
HardCode
spacer


More than just a guestbook

Scenario: You are asked by your boss to create a guestbook for your company and you already have the form that accepts some data from visitors as well as the script that validate those data and put those data on the database. The only task left for you to do is to display those guestbook entries submitted by your company’s visitor.

In layman’s term, all you have to do to accomplish your task is to query the database and loop thru the dataset returned on your query. That task is very simple, right? It’s not that very simple on a programmer’s perspective because the task also includes connecting to the database, followed by executing the query and closing the connection.

 

After that, we should check if the dataset was indeed returned by the database and if true then proceed to loop on that dataset; if false then you can either do nothing or display a notice informing the user that the database returned nothing but I were to choose I would rather display a notice than do nothing because that helps them know that there was nothing to be displayed. After that your guestbook is already done and have the basics of accepting, saving and displaying those guestbook entries and you can already stop there but why you should stop when you can still add a few more that will surely make it even better.

 

So, what are we waiting for let’s add a few more flavor with our guestbook. One of the things we can do is to add a background color and we can easily accomplish that by adding the attribute bgcolor on the table tag with value is either a hexadecimal value of a color or the name of the color itself but we want to do more than just adding a background color.

 

What if we display all the entries in such a way that the background varies after each entries? That will surely make it even better design wise. How can we accomplish that? We can easily accomplish that using an if-then-else statement and by initializing a variable that we will use on the if-then-else statement and at the same time we will increment it by one every time we loop on the dataset. Using the code we use for the guestbook, we will initialize a variable of any name you can think of just make sure it is descriptive enough but if your in a hurry then just use a single letter right above the loop.

 

The next thing we should do is to have the if-then-else statement check if the variable that we initialized has a remainder when we divide it by two. But why should we use two? It is because we are going to display the guestbook entries with alternating background color and therefore we will use two different colors.

 

Back on the if-then-else, we will use the modulus operator (%) that determine if there’s a remainder on the integer in the left side when divided by an integer on the right side of the operator. After that we can set a variable that will serve as the background color for the current row of the dataset. You can also use two CSS class instead of the background color but this time your not going to define the bgcolor tag of the tr tag and instead you will define the class attribute of the td tag wherein the value is the variable you set on the if-then-else statement.

 

We can still add a few more functionality to our guestbook but this article is long enough that I decide to have that for the next article so expect another article will come out next week. You can send feedback to albert.tagaban@gmail.com.

Printer Friendly Version spacer Email to a friend
 

spacer
OTHER TECHNEWS NEWS
spacer
spacer
spacer
spacer
 

spacer




HOME | SUBSCRIBE | ADVERTISE | CONTACT US | SEARCH | ARCHIVE | FEEDBACK

FEATURES: MB WAP | MB Mobile Edition | Desktop Headlines

SECTIONS: MAIN NEWS | BUSINESS | OPINION & EDITORIAL | SPORTS | YOUTH & CAMPUS | ENTERTAINMENT | AGRICULTURE | INFOTECH | HEALTH | TOURISM | SOCIETY | METRO & NATIONAL NEWS | PROVINCIAL NEWS | MOTORING SECTIONS | SCHOOLS COLLEGES AND UNIVERSITIES | WELL BEING | TECHNEWS | TASTE | WEDDINGS | I | BOARD PASSERS |

LINKS: PHILIPPINE PANORAMA | TEMPO | CLASSIFIED ADS ONLINE | USER PRIVACY POLICY

Copyright © 2001-2005, Manila Bulletin. All Rights Reserved.

designed and developed by
Alchemy Solutions