MySQL
  Home arrow MySQL arrow Page 2 - Building a Search Engine with MySQL an...
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

Building a Search Engine with MySQL and PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 18
    2007-07-31

    Table of Contents:
  • Building a Search Engine with MySQL and PHP 5
  • Creating the front end
  • Performing searches with MySQL and PHP 5
  • Assembling the modules of the MySQL-driven search application

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    Building a Search Engine with MySQL and PHP 5 - Creating the front end
    (Page 2 of 4 )

    A logical point to start building this MySQL-driven search application is with creating a basic front-end. It will be comprised of a simple online form into which users will be able to enter different search terms. Naturally, these search terms will first be inserted into a "SELECT" query, and then used to return to the client the corresponding database results, assuming the search has been successful.

    Thus, keeping in mind this requirement, below I listed the signature of a simple (X)HTML file, called "form.htm." It simply displays the search online form that I mentioned a few lines above.

    Here's the definition for this brand new file. Please take a look at it:

    (definition of "form.htm" file)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-
    8859-1" />

    <title>MySQL-based Search Engine</title>

    <link href="default.css" rel="stylesheet" type="text/css" media="screen" />

    <script language="javascript" type="text/javascript">

    window.onload=function(){

    if(document.getElementById&&document.
    getElementsByTagName&&document.createElement){

    var sfield=document.getElementsByTagName('form')[0].elements[0];

    if(!sfield){return};

    sfield.onfocus=function(){this.value=''};

    sfield.onblur=function(){

    if(!this.value){this.value='Enter your search term here'};

    }

    }

    }

    </script>

    </head>

    <body>

    <h1>MySQL-based Search Engine</h1>

    <div class="maincontainer">

    <form method="get" action="processform.php">

    <input type="text" name="searchterm" title="Enter your search
    term here" value="Enter your search term here"
    class="searchbox" />

    <input type="submit" name="search" title="Search Now!
    "value="Search" class="searchbutton" />

    </form>

    </div>

    </body>

    </html>

    As you can see, the above (X)HTML file simply displays a typical text input box that lets users enter different search terms. These terms will be properly processed by MySQL to retrieve some database records. I decided to spice up the form in question with some JavaScript code to make it a bit more interactive.

    So far, so good right? Now that you know how the basic structure has been created, please take a look at the signature of the following "default.css" CSS file, which is tasked with improving the look and feel of the online form.

    Here's how this brand new CSS file looks:

    (definition of "default.css" file)

    body{

    background: #ccc;

    margin: 0;

    padding: 0;

    }

    h1{

    width: 375px;

    padding: 10px;

    margin-left: auto;

    margin-right: auto;

    background: #339;

    font: normal 18px Arial, Helvetica, sans-serif;

    color: #fff;

    border: 1px solid #000;

    text-align: center;

    }

    h2{

    font: bold 18px Arial, Helvetica, sans-serif;

    color: #339;

    }

    p{

    font: normal 10pt Arial, Helvetica, sans-serif;

    color: #000;

    }

    a:link,a:visited{

    font: normal 10pt Arial, Helvetica, sans-serif;

    color: #00f;

    text-decoration: none;

    }

    a:hover{

    color: #f00;

    text-decoration: underline;

    }

    .maincontainer{

    width: 375px;

    padding: 10px;

    margin-left: auto;

    margin-right: auto;

    background: #f0f0f0;

    border: 1px solid #000;

    }

    .rowcontainer{

    padding: 10px;

    margin-bottom: 10px;

    background: #ccf;

    }

    .searchbox{

    width: 200px;

    font: normal 12px Arial, Helvetica, sans-serif;

    color: #000;

    }

    .searchbutton{

    width: 80px;

    font: bold 12px Arial, Helvetica, sans-serif;

    color: #000;

    }

    As shown above, the previous CSS file declares some basic styles which are quite useful for providing the online search form with a decent visual appearance. And speaking of that, the screen shot below illustrates very clearly how the web form looks after applying to it the previous CSS styles:

    Al right, at this stage I have built a primitive front-end for entering different search terms. These terms will be embedded into a SELECT query and then processed by MySQL to return to the client the corresponding search results when possible.

    In this case, the searching procedure will be performed on the web server with the assistance of some PHP classes. In the section to come I'll be showing you the respective signatures for these classes.

    Please click on the link below and keep reading to see how these brand new PHP classes will be defined.

    More MySQL Articles
    More By Alejandro Gervasio


       · In this first oart of the series, the basic structure of this PHP 5-based search...
       · Is there a way to weight the results? For example, if the 'firstname' col is a...
       · Thank you for commenting on my PHP article. Regarding your question, it's possible...
       · Excellent, thank you. (i will probably have some questions for you on that...
       · Again, thank you for your comments.Regards.
       · Again, thank you for your comments.Regards.
       · This system is WAY too complicated. It really doesn't need to be this complex.How...
       · Thank you for commenting on my PHP article. Yes, the code sample you listed...
       · I'm not getting any result out of this code and I don't find the assignment for...
       · Thank you for commenting on my PHP article. Actually, this search engine works just...
       · Thanx I knew what's going on now actually it's my fault cause I made a dump mistake...
       · Thank you for the comments on my PHP article. And I'm glad to know you fixed up the...
       · I have all the code as shown and the MySQL is the right type etc, but when I click...
       · Thank you for commenting on my PHP article. Concerning your question, as I expressed...
       · Thank you for writing this tutorial. I am still learning about classes and don't...
       · very nice articles. simple, effective and extremely useful. it's exactly what our...
     

       

    MYSQL ARTICLES

    - MySQL Table Prefix Changer Tool in PHP
    - Using the SIGNAL Statement for Error Handling
    - Error Handling Examples
    - Error Handling
    - Completing a Search Engine with MySQL and PH...
    - Paginating Result Sets for a Search Engine B...
    - Building a Search Engine with MySQL and PHP 5
    - Using Boolean Operators for Full Text and Bo...
    - PHP, MySQL and the PEAR Database
    - Working with PHP and MySQL
    - Getting PHP to Talk to MySQL
    - Creating an RSS Reader: the Reader
    - MySQL Security Overview
    - Creating the Admin Script for a PHP/MySQL Bl...
    - Creating the Blog Script for a PHP/MySQL Blo...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway