Jump to content

Use results from MySql Search to Search another MySql Database can it be done?


richiejones24

Recommended Posts

Something like this?

 


$query1 = mysql_query("SELECT key FROM db1 WHERE something = 'something'") or die(mysql_error());

if( mysql_num_rows($query1) >= 1 ) {

   while( $row = mysql_fetch_array($query1) ) {
      $searchKey = $row['key'];
   }

   $query2 = mysql_query("SELECT key FROM db2 WHERE something = '$searchKey'") or die(mysql_error());

} else { 

   echo "nothing found";

}

Link to comment
Share on other sites

Thanks for your reply's, let me clarify what i am trying to do, I have a dating site and i have added the option to upgrade your profile so it is displayed on the homepage so I have created a new MySql table with the users username and the upgrade options they have selected. so what i won't to do is search the upgrade table (SELECT * FROM upgrade WHERE upgrade_one = '1') which will give me all the user names of all the user who have upgraded, then i won't to search the user table with the username (i got from the first search) to pull there profiles of the upgraded users.       

Link to comment
Share on other sites

Something like this?

 


$query1 = mysql_query("SELECT key FROM db1 WHERE something = 'something'") or die(mysql_error());

if( mysql_num_rows($query1) >= 1 ) {

   while( $row = mysql_fetch_array($query1) ) {
      $searchKey = $row['key'];
   }

   $query2 = mysql_query("SELECT key FROM db2 WHERE something = '$searchKey'") or die(mysql_error());

} else { 

   echo "nothing found";

}

 

Thanks For the Reply!

This is not exactly what i need as the original search will bring multiple results (user names) so the second search I need it to do something like this ("SELECT key FROM db2 WHERE something = '$searchKey' OR something = '$searchKey' OR something = '$searchKey' OR something = '$searchKey'  ")

 

in some kind of array ive tried using "WHILE" and "FOREACH" but i cant figure out how to do it or whether it can be done.   

Link to comment
Share on other sites

Why would you make a 2nd table, when you could just add a status column to the users table to indicate whether they are "upgrade" users?

Its complicated but i cant do that it has to run on its own table.

 

What exactly is complicated?

 

The User profiles are spread over 5 tables and i use  MySql Join and the username to pull all the information from the tables to make the profile. If i added the upgrade option to one of the tables all i would be able to to is get the information from that table which would be useless i need the username to get the rest of the profile from the different tables.

Link to comment
Share on other sites

No, it sounds like you have a typical relational model where you have related information in seperate tables.  That is normal.  Using joins you can unite the information in one query.  If your user table has a column that indicates this membership status, then all you need do is specify that as criteria either as part of the join condition or in the where clause, and you'll get the result you are looking for. 

 

It is hard for us to advise you more specifically on how to do this type of query without understanding your schema more fully but I assure you that a seperate table is not needed, and not a good design choice.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.