PHPBuilder - Mass Customization Page 3



RSS Twitter
Articles Application Architecture

Mass Customization - Page 3

by: Jim King
|
November 2, 2000

Using this information to customize the page is now easy. For example, let's say that I have a database of ads. I only want the ads specific to the state of Wisconsin to be shown to visitors from Wisconsin. So I write a short if statement that says if the visitor is from Wisconsin, then display the Wisconsin ads. Like this:

<?php

if( $thelead[state] == WI) {
    
//code to display Wisconsin ads
} else {
    
//code to display random generic ads
}

?>
Now that we know how to use the collected information, let's see how to collect the information.
Collecting information on visitors is accomplished utilizing the various forms on a web site. For example, a web site that sells products online could use this application to grab the state from a visitor during the check out procedure or when a visitor subscribes to an email newsletter. The point is, information is only gathered from an existing form. This is done by using the addItem() method of the lead class. The addItem() method takes as arguments the database column to store the data being collected (in our case state), the value of the data being collected (in our case the visitors two digit state abbreviation), and finally the value of the cookie that identifies the visitor.
Again, you must instantiate the class, verify the cookie is set and then add the data to the database.

<?php

mylead 
= new lead("dbhost""database""dbusername""dbpassword""leadstablename");

if(!isset(
$HTTP_COOKIE_VARS[lead])) {
    
$sid $mylead->setCookie();
    
$result $mylead->additem("state"$state$sid);
} else {
    
$result $mylead->additem("state"$state$HTTP_COOKIE_VARS[lead]);
}

?>
That's all there is to it. The nice thing about this application is that you can define what information you would like to collect and it is saved and retrieved from the database using the same class methods each time. One thing I did not go over was error handling. Error handling is accomplished by using the error class internal to the leads class. The additem() method will return an object with all the error information in it. The error information is $result->errno, the error number 1 for success and 0 for failure, $result->errstr, an explanation of the error, and $result->method, the method that the error occurred in.
Customizing a visitor's experience is increasingly more important to keep the visitors attention and generate sales. I hope to find the time to expand this article in the future.
-- Jim

« Previous Page
1
|
2
|
3

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Jim King

Comment:



Comment:

(Maximum characters: 1200). You have characters left.