HomeMySQL Completing a Search Engine with MySQL and PHP 5
Completing a Search Engine with MySQL and PHP 5
Building database-driven web sites is one of the most popular trends today in web site development. However, this approach implies that potential visitors must be provided with a straightforward mechanism that allows them to search through web site content. This three-part series walks you through the process of building an expandable search engine by using the combined functionality of MySQL and PHP 5.
As you'll possibly recall, over the course of the preceding article of the series I defined a couple of basic MySQL-processing classes. These classes came in handy not only for performing different search queries against one or more selected databases, but for displaying the corresponding results using chunks of paginated data. I used the object-oriented paradigm to develop the search engine, but this isn't mandatory since the same level of functionality can also be achieved by utilizing a procedural approach.
Having clarified that crucial point, aside from refreshing some important concepts concerning the development of this MySQL-based search engine, I think now is a good time to discuss the topics that I plan to address in this last installment of the series. This way you'll know what to expect from this tutorial.
In the previous article I showed you how to spawn the results returned by a specific search query across different web pages, so in this last part of the series I'm going to complete this search application by fixing a concrete issue associated specifically with paginating MySQL data sets. Put in a simple way, each time that a user performs a search and then clicks on the paginated links to browse the corresponding results, the original search string passed to the application is simply no longer available in subsequent web page requests. This is something that can quickly break the functionality of the search engine.
Of course, there are many ways to solve this problem, such as appending the search terms to the query string generated by the corresponding paginated links. However, in this case I'm going to take a slightly different approach, and use a simple session mechanism to maintain the value of the search string across different web pages. Naturally, you're free to use the method that best suits your personal needs.
All right, with the preliminaries already out of our way, let's take the last step involved in building this MySQL-based search engine. Let's get started!