Skip to main content
Participating Frequently
January 3, 2010
Question

Matching data in two databases

  • January 3, 2010
  • 1 reply
  • 584 views

Hi

I am trying to collect data from one database and match the result of the first datatbase to the second databases data. I Then want to echo the matches ranked based on the number of matches found for the individual variables. The echo would have a maximum of 20 results.

This is some of my early trials could some one help me please.

<? Php

connect=include('connect.php')

//This code sets the current logged in individual.
$id= $_SESSION['id'];

$person=mysql_query("SELECT * FROM Users WHERE id='$id'")

//This echos the data results from the database query.
while($row=mysql_fetch_assoc($person))
{
echo ' $rows['age'];

       $rows['country'];

       $rows['city'];

       $rows  

}
// This querys the second database. The plan is to display and rank at least 20 results based on how closely
they match the first queries results. I first created viarables of the first database results.

$age=$rows['age'];
$country=$rows['country'];
$city=$rows['city'];

// This queries the second datbase.

$account=mysql_query("SELECT * FROM account WHERE ages='$age', country='$country' city='$city'")

//This echos the result
while($num=mysql_fetch_assoc($account))
{
echo 'num['age'];
      num['country'];
      num['city'];';
      num['otherdata'];
}
// otherdata variable output other data in the database from the multiple echoed results.





I want to limit the results to 20 and rank them according to the most matching from first database results. Please help. Just reply if any part does make sense.

This topic has been closed for replies.

1 reply

Participating Frequently
January 3, 2010

I don't use MySQL but many DBMS's allow you to select from multiple databases. That would be the easiest solution. Are both databases running on the same instance of MySQL?

Participating Frequently
January 6, 2010

its the same database but different tables.

Participating Frequently
January 6, 2010

If they are in the same database then you would use a simple join. But it is not clear from your requirements how you are trying to 'match' the fields in the two tables. You would need to post detailed requirements for us to be of any help. Some context would also be helpful.