Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
its the same database but different tables.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Its abite complicated to explain. I will have to do a constant trial and error . Thanks for the reply.