Jump to content


Photo

percent formatting problem


  • Please log in to reply
No replies to this topic

#1 vzwhaley

vzwhaley
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 03 April 2006 - 04:45 PM

How do you format the relevance or score in results from a full text MySQL search? I just can't seem to get the math correct. My results are displaying fine, and I realize that the results are sorted based on the highest relevance or score, but I would like to display the relevance, such as 100%, 99%, etc. and have the number rounded so the viewer can see for themselves how high the ranking is for a certain search. Any suggestions would be much appreciated. Thanks!

[PHP]<? 
$strTemp = trim($_REQUEST['txtSearch']);

  mysql_select_db($database);
  $sql = "SELECT *, MATCH(Name) AGAINST ('$strTemp') AS score FROM ObitData WHERE MATCH(Name) AGAINST('$strTemp') ORDER BY score DESC";

while ($Search = mysql_fetch_array($Recordset1)) { 

$val = round(($Search['score'] / mysql_num_rows($Search)) * 100);

echo "Result: " . $val . "% " . $Search['Name'] . "<br>";
}
?>[/PHP]





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users