Jump to content

[SOLVED] need some help with php and mysql...


CSmith1128

Recommended Posts

Hello. I am using multiple databases on my site.

 

I was wondering if it were possible to select something from a database based on information from another database..

 

for example..

i want to select the user_id of a user where their age (found in database 1) is 28 and the gender of that person (found in database 2) is male.

 

is this possible?

 

i am trying to do it in 1 query, if thats possible..

if not, thats fine.. whatever works and is most efficient.

 

thanks!!

Link to comment
https://forums.phpfreaks.com/topic/85619-solved-need-some-help-with-php-and-mysql/
Share on other sites

SELECT a.userID

FROM database1.table1 a

INNER JOIN database2.table2 b ON a.userID = b.userID

WHERE a.age = 28

AND b.gender = 'male'

 

 

what is the 'a' and 'b' in there for?

what do they represent?

im not as familiar with JOINS as i should be and i am confused right there..

 

thanks!

okkkkk.. now i have a connection problem i believe..

 

when i try to access the information from both databases, this is the error i receive...

 

SELECT command denied to user 'this_user'@'localhost' for table 'userTable'..

 

do you know why this is?

 

thanks!

$mysql_database="this_db";

$mysql_username="user";

$mysql_password="password";

 

$dbcnx = mysql_connect("localhost",$mysql_username,$mysql_password) or die("Unable to Connect to the Server at This Time... Please Try Again Later.");

mysql_select_db($mysql_database, $dbcnx) or die ("Unable to Connect to the Server at This Time... Please Try Again Later.");

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.