For every record in the results of the link table, the content id and number of occurrences is stored in an
associative array
id already exists in
occurrence value.
associative array
$contArray
. During ‘while loop operation’, if the contentid already exists in
$contArray
, the occurrence is incremented with this newoccurrence value.
Now
Otherwise, the program skips to the next part that displays the result ??NO RESULTS FOUND??
$contArray
is set and it shows that some results are found in the database table.Otherwise, the program skips to the next part that displays the result ??NO RESULTS FOUND??
<?php
if(isset($contArray)){
//declare an array to store the results
$FoundRef=array();
//Sort array in desending order of the key value
arsort($contArray,SORT_DESC);
//Store the results in the $FoundRef Array
//code for this is given in the next line.
}
?>
In the next step we have to fetch title, the first 200 words in content table, into an array
$FoundRef
.
<?php
foreach($contArray as $cont){
$rank=$cont["wrank"];
if (
$rank == $noofSearchWords ) {
$contentId = $cont["id"];
$occurances = $cont["oc"];
$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
} //end of for each
?>