Re: [PHP] Re: find (matching) person in other table



Jared Farrish wrote:
I was thinking to assign points (percentage) to matching fields (last
name, first name, email, phone, city, zip, phone) and then list people
with more than 50%. e.g., if first and last name match - 75%, if only
email match - 85%, if first name, last name and email match - 100%, if
last name and phone match - 50%... etc.

does anybody have any experience with such a problem? or something
similar?

Although you should be able to do this with you SELECT (I guess, never
have), since you posted this to a PHP mailing, you get a PHP answer!

Look up Levinshtein in the php manual and start from there:

http://us2.php.net/manual/en/function.levenshtein.php

If you can do this on SELECT (using the db engine), I would suggest that, as
that way you don't have to return a giant list to poke through.

You can also use wildcards, and only select matches that have the first
three characters:

$lastname = strpos('Rogers',0,2);
$firstname = strpos('Timothy',0,2);
$select = "SELECT `uid`,`LastName`,`FirstName`
FROM `users`
WHERE LastName='$lastname%'
AND FirstName='$firstname%'";

I haven't tested that, but I think it would work. You would need to work on
a way to LIMIT the matches effectively. If that doesn't work, hey, this is a
PHP list...
yes. in one hand it's more for mysql list. though, I was thinking more if somebody had already something similar as a "project". more as path I have to follow.
e.g., in your example, in where clause AND doesn't work because bob could be robert too, right? and last name has to match 100%, right? (or I'm wrong?)
how "smart" solution will be something like this:

$query = my_query("select id from members where last_name='$last_name'");
while($result = mysql_fetch_array($query))
{
$MEMBERS[$result['id']] += 50;
}

$query = my_query("select id from members where first_name='$first_name'");
while($result = mysql_fetch_array($query))
{
$MEMBERS[$result['id']] += 10;
}

$query = my_query("select id from members where email='$email'");
while($result = mysql_fetch_array($query))
{
$MEMBERS[$result['id']] += 85;
}
etc.

after last query I will have an array of people. and I'll list all person with "score" more than 50.

or, since last name MUST match, I think it's better this way (just got in my head):
$query = my_query("select id from members where last_name='$last_name'");
while($result = mysql_fetch_array($query))
{
$query = my_query("select id from members where first_name='$first_name'");
while($result = mysql_fetch_array($query))
{
$MEMBERS[$result['id']] += 10;
}

$query = my_query("select id from members where email='$email'");
while($result = mysql_fetch_array($query))
{
$MEMBERS[$result['id']] += 85;
}

etc.
}
.



Relevant Pages

  • Re: Confused by mysqli
    ... When I started using MySQL with Perl back in 1998, ... fetch_assocon a query I prepared with bind variables, ... So I had it print out its eval string that it was trying to run. ... PHP will fail to run at all, because bind_result will not have enough ...
    (comp.lang.php)
  • Re: [PHP] PHP & MySQL Problem
    ... [PHP] PHP & MySQL Problem ... > actually there seems to be no problem with your query (besides that you ...
    (php.general)
  • Re: timestamp
    ... PHP newsgroup, and should be discussed in comp.databases.mysql). ... Then click on the Survey link."; ... your SQL syntax; check the manual that corresponds to your MySQL ... Your query fails because a datetime value needs to be in single quotes in the query, ...
    (comp.lang.php)
  • Re: [PHP] Architecture patterns in PHP
    ... 316 Query SHOW TABLES FROM `cake` ... 316 Query DESCRIBE `posts` ... Application and Templating Framework for PHP ... when they cache the results of reverse engineer the object model from ...
    (php.general)
  • Re: [PHP] PHP & MySQL Problem
    ... [PHP] PHP & MySQL Problem ... The query then just goes like ... >> I have a script that collects data from a form and puts together a>> mysql ...
    (php.general)