Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Matching data in two databases

Explorer ,
Jan 03, 2010 Jan 03, 2010

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.

TOPICS
Server side applications
541
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 03, 2010 Jan 03, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 05, 2010 Jan 05, 2010

its the same database but different tables.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 05, 2010 Jan 05, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 10, 2010 Jan 10, 2010
LATEST

Its abite complicated to explain. I will have to do a constant trial and error . Thanks for the reply.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines