#native_company# #native_desc#
#native_cta#

Dynamic Document Search Engine – Part 1 Page 11

By M.Murali Dharan
on February 17, 2004

Sort the array in descending order of the key value. This will order from highest occurrences to the lowest. For example,
if the number of search words is four, the order is displayed 4 then 3 then 2 and last 1.
//Sort array in descending order of the key value
                arsort($contArray,SORT_DESC);
In the next step we have to fetch title, first 200 words in content table in to an array
$FoundRef
.

<?php

//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.

<?php

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) == " reference" " references");

    echo 
" found";

    echo 
"<p>";

if(
$junkWords){

        echo 
"Common words like";

        foreach(
$junkWords as $jWords){

            echo 
"&nbsp"."'".$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=<?php echo $FoundRef[$a]["contid"]?>"><emp><b><?php echo $FoundRef[$a]

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

            <br /><small><?php echo $FoundRef[$a]["summary"?>...</small><br /><br />

            <?php echo "</td></tr>";

            echo 
"</table>";

    }

}
//end of isset FoundRef

?>



1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9
|
|
11
|
|