HomeMySQL Page 3 - Completing a Search Engine with MySQL and PHP 5
Defining a simple web page generating class - MySQL
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 I stated in the prior section, the last task required to complete the development of this search application consists of building a simple yet effective web page generating class. This class will be responsible for creating the web documents required to display the results returned by a specified search query.
Of course, the definition of this brand new PHP class is entirely optional in this case, since the respective database results can be also shown by using a procedural approach instead of the object-oriented one that I'm explaining here. Nevertheless, I'd like to show you the signature for this class, regardless of the method that you may want to use for displaying the search results.
Given that, here's how this web page generating class looks:
<?php class WebPage{ private $title; public function __construct($title='MySQL-based Search Engine'){ $this->title=$title; } public function displayHeader(){ return '<html><head><title>'.$this->title.'</title><link href="default.css" rel="stylesheet" type="text/css" /></head>'; } public function displayBody($content){ return '<body>'.$content.'</body>'; } public function displayFooter(){ return '</html>'; } } ?>
Quite simple, right? As you can see, the signature for the above "WebPage" class doesn't bear too much discussion. It performs a few simple tasks, such as building the header, body and footer sections of a typical web document. Therefore, assuming that you won't have major problems understanding the way that this class works, it's time to move forward and develop a hands-on example, where you'll be able to see how this MySQL-driven search engine does its business.
To learn how this practical example will be created, please click on the link below and keep reading.