MySQL
  Home arrow MySQL arrow Page 4 - Developing A Site Search Engine With PHP A...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
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

Developing A Site Search Engine With PHP And MySQL
By: Mitchell Harper
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 91
    2002-02-16

    Table of Contents:
  • Developing A Site Search Engine With PHP And MySQL
  • Search Engine Theory
  • Creating the database
  • The searchdocs.php script
  • The doSearch function
  • Testing our search script
  • Conclusion

  • 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


    Developing A Site Search Engine With PHP And MySQL - The searchdocs.php script


    (Page 4 of 7 )

    Our PHP search script will be fairly simple, and will be used to demonstrate one way of retrieving records from the articles table based on selective keywords. Create a new script named searchdocs.php and save it in a directory that Apache can process. Enter the framework code for our search routine into searchdocs.php:

    <?php

    $submit = $_POST["submit"];

    $keywords = $_POST["keywords"];

    if(isset($submit) || isset($keywords))

    {

    doSearch($keywords);

    }

    else

    {

    getKeywords();

    }

    function getKeywords()

    {

    }

    function doSearch($search_keywords)

    {

    }

    ?>


    Our search script starts out by assigning the values of two form variables collected from the $_POST associative array to local variables, $submit and $keywords. In PHP v4.1 and later, the $HTTP_POST_VARS[] associative array has been deprecated and it's recommended that you use the $_POST associative array instead (see this link for more info).

    By default, the $submit variable will contain no data, and will thus be unset, so the getKeywords function will be called. Enter the following code into the getKeyWords function:

    function getKeywords()

    {

    ?>

    <html>

    <head>

    <title> Enter Search Keywords </title>

    </head>

    <body bgcolor="#FFFFFF">

    <form name="frmKW" action="searchdocs.php" method="post">

    <h1>Keyword Search</h1>

    Enter keywords to search on:

    <input type="text" name="keywords" maxlength="100">

    <br><br><input type="submit" name="submit" value="Search">

    </form>

    </body>

    </html>

    <?php

    }


    The getKeyWords function allows the user to enter keywords into a text box and looks like this:

    The results of the getKeyWords function

    When the search button is clicked, the name and value of the text box and submit button is passed back to our script. Recall earlier that the getKeyWords function is called when isset($keywords) is false.

    This time round, $keywords (which is the value of the text box from PHP's $_POST associative array) contains some data, and so the doSearch function is called instead, passing $keywords in as its parameter.

    More MySQL Articles
    More By Mitchell Harper


     

    MYSQL ARTICLES

    - MySQL and BLOBs
    - Two Lessons in ASP and MySQL
    - Lord Of The Strings Part 2
    - Lord Of The Strings Part 1
    - Importing Data into MySQL with Navicat
    - Building a Sustainable Web Site
    - Creating An Online Photo Album with PHP and ...
    - Creating An Online Photo Album with PHP and ...
    - PhpED 3.2 – More Features Than You Can Poke ...
    - Creating An Online Photo Album with PHP and ...
    - Creating An Online Photo Album with PHP and ...
    - Security and Sessions in PHP
    - Setup Your Personal Reminder System Using PHP
    - Create a IP-Country Database Using PERL and ...
    - Developing a Dynamic Document Search in PHP ...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT