Creating a Search Application -
(Page 22 of 29 )
The first task in the constructor is to connect to the database. We will, again, use the database class from earlier in this tutorial. Second, we will add slashes to the search terms provided to this function if the magic_quotes_gpc directive is not turned on. Then, we will separate the search terms and store them in a class variable as an array. If only one word was entered, we will end up with an array of only one element. Last, we will store the number of search terms in a class variable.
<?php function Search($keywords) { $this->_db = new DB_Class('test', 'username', 'password'); if (!get_magic_quotes_gpc()) { $keywords = addslashes ($keywords); } $this->_searchterms = explode(' ', $keywords); $this->_numterms = count($this->_searchterms); } ?> |
Next: >>
More Database Articles Articles
More By Matt Wade