HomeMySQL Page 4 - Paginating Result Sets for a Search Engine Built with MySQL and PHP 5
Maintaining the value of a given search term across different web pages - MySQL
If you're a PHP developer looking for an approachable guide on how to build an expandable search engine with MySQL and PHP 5, then this series of articles might be quite useful to you. Welcome to the second installment of the series that began with "Building a Search Engine with MySQL and PHP 5." These tutorials will show you how to create a fully functional search application by using the capabilities provided by the MySQL/PHP 5 team.
As I expressed in the section that you just read, the last step that I'm going to take for the moment will consist of building a basic session handling class. This class will come in useful for maintaining the value of a given search string across the different web pages generated by the page links that you learned before.
With the session handling class, each time an user performs a search against one or more selected databases, the search terms will be kept when clicking on the page links. Quite simple, isn't it?
That being said, here is the signature of this brand new session handling class:
class SessionHandler{ public function __construct(){ session_start(); } public function setVariable($value='default',$varname='default'){ $_SESSION[$varname]=$value; } public function getVariable($varname='default'){ if(!$_SESSION[$varname]){ return false; } return $_SESSION[$varname]; } public function destroy(){ session_start(); session_unset(); session_destroy(); } }
As you can see, the above session handler presents a few basic methods for registering and deregistering session variables, in addition to destroying a complete session. This class is the one that I'm going to use in conjunction with the others defined earlier to implement a fully functional searching application. However, the completion of this MySQL-driven search engine will be done in the last tutorial of the series.
Final thoughts
In this second article of the series I explained in detail how to add result pagination capabilities to the existing MySQL-based search engine by incorporating some basic methods into the "Result" class that was developed in the first tutorial. I also defined a brand new session handling class for maintaining the value of a given search string across different web pages.
Thus, the next logical step will consist of putting all these classes to work together, in this way completing the development of this expandable search application. Naturally, this will be done in the last part of the series, so you don't have any excuses to miss it!