SunQuest
 
       MySQL
  Home arrow MySQL arrow Page 4 - Developing a Dynamic Document Search in PH...
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  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
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 Dynamic Document Search in PHP Part 1/2
By: Murali Dharan
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 16
    2003-06-26

    Table of Contents:
  • Developing a Dynamic Document Search in PHP Part 1/2
  • The Article
  • The Article (contd.)
  • The Article (contd.)
  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Developing a Dynamic Document Search in PHP Part 1/2 - The Article (contd.)


    (Page 4 of 5 )

    //Sort array in descending order of the key value
                    arsort($contArray,SORT_DESC);

    In the next step we have to fetch the title and first 200 words from the content table into an array called $FoundRef:

    //declare an array to store the results
                    $FoundRef=array();

    while(list($contentId,$occurances)=each($contArray)){

                $aQuery = "select contid,title,left(abstract,200) as summary from content where contid = " . $contentId;
                $aResult = mysql_query($aQuery);

                if(mysql_num_rows($aResult) > 0){
                    $aRow = mysql_fetch_array($aResult);
                    $FoundRef[] = array (
                                      "contid" => $aRow["contid"],
                                      "title" => $aRow["title"],
                                      "summary" => $aRow["summary"],
                                      "occurance"=>$occurances
                    );
                    }//end of  if
                }

    Finally, we have to display the results in the browser. Here is the code:

    if(isset($FoundRef))
                {
                    echo "<table width=\"100%\"><tr><th class=\"title\">Search Result</td></tr></table>";
                    echo "<a href=\"#\" onclick=\"history.back()\">Back</a>";
                    echo "<br>";
                    echo sizeof($FoundRef);
                    echo (sizeof($FoundRef) == 1 ? " reference" : " references");
                    echo " found";
                    echo "<p>";
         if($junkWords){
                        echo "Common words like";
                        foreach($junkWords as $jWords){
                            echo " "."'".$jWords."'";
                        }
                        echo "are removed from the search string";
                    }
                    echo "</h5>";
                    foreach($FoundRef as $a => $value)
                    {
                        echo "<table>";
                        echo "<tr><td valign=\"top\">";
                       // echo $FoundRef[$a]["contid"];
                        ?>

                            <a href=showref.php?refid=<? echo $FoundRef[$a]["contid"]?>><emp><b><? echo $FoundRef[$a]["title"]?></b></emp></a><div align="right"> Occurance(s): <? echo $FoundRef[$a]["occurance"] ?></div>

                            <br><small><? echo $FoundRef[$a]["summary"] ?>...</small><br><br>
                            <? echo "</td></tr>";
                    }?>


                    <?
                        echo "</table>";
                }//end of isset FoundRef

    The HTML page to get input from user is shown below:

    <html>
    <head>
    <title>Search Engine</title>
    <style type="text/css">

    body{ font-size:20; font-weight:bold; font-stretch:semi-expand; font-family:MSserif; color:#0066CC; background-color:#EEEEE4;
    align:center; background-color:white }
    h4{   background-color:#0066CC;     color:#FFFFFF;   font-family:verdana;  }
    h3{  color:#0066CC;   }
    th{  background-color:#6996ED;  color:#FFFFFF;  font-family:Arial;   }
    a{text-decoration:none;}
    </style>
    </head>
    <body>
        <?php
    if($submit)
    {
        if(!$keywords){
            $errmsg="Sorry, Please fill in search field";
            form($errmsg);
        }else{
               //Start Timer
                $start = getmicrotime();

              //PERFORM SEARCH OPERATION AND DISPLAY RESULT
            }else {
                //end Timer
                $end = getmicrotime();

                //TOTAL TIME TAKEN TO DO SEARCH OPERATION
                $time_taken=(float)($end-$start);
                $time_taken=number_format($time_taken,2,'.','');

                echo "<p>Your Query Executed in $time_taken Seconds";

                $errmsg="<p>No Search result found for '$keywords'";
                echo $errmsg;
                echo "<br><a href=\"#\" onclick=\"history.back()\">Back</a>";
            }//endof isset ref
        }//end of if key word exists
    } else{  //display the form
        form($keyword);
    } //END OF FORM DISPLAY ?>
    </body>
    </html>
        <?
    function form($errmsg)
    {  ?>
        <h4 align="center">Search Engine</h4>
            <b><? echo $errmsg; ?></b>
            <center>
            <form method=POST action=<? echo $PHP_SELF ?>>
            </div>
            Enter keywords to search on:
            <input type="text" name="keywords" maxlength="100">
            <input type="submit" name="submit" value="Search">
            </form>
            </body>
            </html>
            <?
    }


    function getmicrotime()
    {
        list($usec,$sec)=explode(" ",microtime());
        return ((float)$usec+(float)$sec);
    }
    ?>

    The function getmicrotime() returns the time in microseconds. This function is called during the start and end of the search process.

    More MySQL Articles
    More By Murali Dharan


       · hi,i am umesh yadav, i am working on php last 6 months but i was developing a...
     

    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 3 hosted by Hostway