Hi
Does somebody know an easy mysql select command or a way in PHP to do searches and display the percentage up on value match in columns?
I have a database with contacts. Now if a user adds a new contact i search, if there are other contacts that are similar in the contacts table. If i have found similar contacts i display them and ask the user, if he means one of these.
Of course i display the percentage of how much columns have matched to the corresponding similar contact.
At the moment i select all my contacts parse the single columns in to an array and then put them all together.
$col // Array with mysql results
// Example values //
$col[0] = "thomas";
$col[1] = "anderson";
$col[2] = "Car Mechanic";
$fulltext = $col[0].$col[1].$col[2];
$part = 100 / 3; // 3 colums
if(ereg("thomas",$fulltext)
{
$percentage += $part;
}
if(ereg("Car",$fulltext)
{
$percentage += $part;
}
$info[col1] = $col[1];
$info[col2] = $col[2];
$info[col3] = $col[3];
$info[percentage] = $percentage;
echo $info[percentage]." ".$info[col1]." ".$info[col2]." ".$info[col3]."<br>";
There are a few bugs that can happen this way. That's why i'm asking.
Also i can't sort directly with mysql sort command.
I'm hoping for better strategies ;-)
Thanks
Chris