$sql = "SELECT DISTINCT term FROM logs WHERE term_soundex LIKE LEFT(SOUNDEX('$trimmed'),4) AND results2 >0 AND term REGEXP '[0-9]' !=1 LIMIT 10";
$result = mysql_query($sql) or die ("
ERROR: ".mysql_error()."");
$x = 0;
echo "";
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
$compare = $row[term];
$levenshtein = levenshtein($trimmed, $compare);
$lengthdifference = max($trimmed, $compare) - min($trimmed, $compare);
$levenshtein-=$lengthdifference;
$similarity = $levenshtein/strlen(min($trimmed, $compare));
$row[] = $similarity;
sort($row, SORT_DESC);
if ($x == 0) // so that table headers are only created on the first pass
{
$col = (count($row)); // counts number of elements in the array
$x=1;
echo "";
for ($y=0; $y<$col; $y++)
{
echo "| ";
echo key($row); // gets the names of the fields
echo " | ";
next($row);
}
echo "
";
}
reset($row);
echo "";
for ($y=0; $y<$col; $y++)
{
echo "| ";
echo current($row);
echo" | ";
next($row);
}
echo "
";
} // end of while loop