Search This Blog

Tuesday, July 7, 2009

Search Engine Function for Websites - 7th July

Today is the birthday for my friend: James! Happy Birthday and don't merepek too much. I'm sure while he's reading this post, he will sure be saying something like 'celaka'...haha...I was the 7th person, so, that makes it: 7th July (7) person number seven...haha..all sevens...

Anyways, I've found out how to make your own search engine for websites. Application includes: keyword search, article search, people search, and item search. It is based on MySQL and also Php, so anyone doing both can follow this method. As for the others, I would like to express my sorrow as I can't help you. So, on to the method.

We have two pages:- search_form.php and search_result.php
search_form.php is where people key-in the search term and press 'SEARCH' while search_result.php is where the results of the search is located. The key point of the method is using the form to 'GET' the data as URL Parameters and sending it over to the Recordset in search_result.php to display results.

Procedures:-
1> Start by creating a database for the table that you want to be searched from.
In other words, it can be any table, as long as there is one column for the Incremental ID and the search term.

2> Then in search_form.php, create a form to get the data from the user. Dropdown lists are also good idea for extra search. This can be done in Dreamweaver through the use of Insert -> Form, then the text-fields etc, but make sure to set the method to GET and action to search_result.php

3> In search_result.php, create a recordset and use the QuB. In the table that shows the table structure, make sure to select the column that you want the search function to check only. Under 'condition' (below), click the right-hand '...' box. In the ensuing window, set condition to "contains", run-time value as "0" and default value as the text-field 'id' created at search_form.php earlier.

4> Go to "Query" menu at top left corner and "save" then "close". Click 'Advanced to see the query something like below:-

SELECT multiply_test.multiply_id (row 1)
FROM multiply_test
WHERE multiply_test.multiply_id LIKE %KTColParam1% (row 3)

change row(1) to " SELECT * " to properly reflect all fields.
and change the %ColParam1% properties of run-time value to $_GET['x'] ,where x is search_term id as mentioned earlier.

5> Walah..the search function is done! You can use multiple search terms by manipulating the MySQL query by adding 'AND' and 'OR' with other columns at row 3.

Hope people reading it can understand it and if not, again, email me!

No comments: