Friday, May 15, 2009

Feeding database with keywords from search engine

In order to improve your understanding of visitor’s needs and wants you may want to collect keywords used in your search engine and periodically analyze the data produced. The following example explains how to collect keywords, submission date and time, as well as the user’s remote address and flag if the search was successful or not.

1. Create a new table in the database. For illustration purposes I am going to use the following convention:
Table Name: search_log
Attributes (columns):
- ID: int(32), unsigned, auto_increment, primary key
- log_data: varchar(30)
- stp_date: date
- stp_time: time
- remote_ip: varchar(16)
- search_success: tinyint(1)

2. Open the following script:
\includes\modules\pages\advanced_search_result\header_php.php

Add the following code: $entry = $_GET['keyword'];
if ($result->number_of_rows > 0) {
mysql_query ("INSERT INTO `search_log` (`Log_Data`,`stp_date`,`stp_time`,`remote_ip`,`search_success`) VALUES ('$entry',now(),now(),'".$_SERVER['REMOTE_ADDR']."','1')");
}else{
mysql_query ("INSERT INTO `search_log` (`Log_Data`,`stp_date`,`stp_time`,`remote_ip`,`search_success`) VALUES ('$entry',now(),now(),'".$_SERVER['REMOTE_ADDR']."','0')");
}

Before the following line:
if ($result->number_of_rows == 0) {

No comments:

Post a Comment