Jump to content


This topic is now archived and is closed to further replies.


percent formatting problem

Recommended Posts

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!

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

  $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>";

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.