CSmith1128 Posted January 12, 2008 Share Posted January 12, 2008 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!! Quote Link to comment https://forums.phpfreaks.com/topic/85619-solved-need-some-help-with-php-and-mysql/ Share on other sites More sharing options...
Barand Posted January 12, 2008 Share Posted January 12, 2008 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' Quote Link to comment https://forums.phpfreaks.com/topic/85619-solved-need-some-help-with-php-and-mysql/#findComment-436944 Share on other sites More sharing options...
CSmith1128 Posted January 14, 2008 Author Share Posted January 14, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/85619-solved-need-some-help-with-php-and-mysql/#findComment-438582 Share on other sites More sharing options...
p2grace Posted January 14, 2008 Share Posted January 14, 2008 They let you substitute the letter for the entire name of the table. So instead of saying database1.table1.age = 28, you can say a.age = 28. Quote Link to comment https://forums.phpfreaks.com/topic/85619-solved-need-some-help-with-php-and-mysql/#findComment-438597 Share on other sites More sharing options...
CSmith1128 Posted January 14, 2008 Author Share Posted January 14, 2008 oh ok good.. i was thinking thats what it meant but i was not completely sure.. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/85619-solved-need-some-help-with-php-and-mysql/#findComment-438600 Share on other sites More sharing options...
CSmith1128 Posted January 15, 2008 Author Share Posted January 15, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/85619-solved-need-some-help-with-php-and-mysql/#findComment-440357 Share on other sites More sharing options...
teng84 Posted January 15, 2008 Share Posted January 15, 2008 may we see your code? I'm suspecting you are not connecting to a database or your connection fails Quote Link to comment https://forums.phpfreaks.com/topic/85619-solved-need-some-help-with-php-and-mysql/#findComment-440360 Share on other sites More sharing options...
Barand Posted January 15, 2008 Share Posted January 15, 2008 Looks like you don't have the correct permissions to access. Quote Link to comment https://forums.phpfreaks.com/topic/85619-solved-need-some-help-with-php-and-mysql/#findComment-440364 Share on other sites More sharing options...
CSmith1128 Posted January 15, 2008 Author Share Posted January 15, 2008 $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."); Quote Link to comment https://forums.phpfreaks.com/topic/85619-solved-need-some-help-with-php-and-mysql/#findComment-440367 Share on other sites More sharing options...
p2grace Posted January 15, 2008 Share Posted January 15, 2008 Where's the $dbcnx variable coming from? Quote Link to comment https://forums.phpfreaks.com/topic/85619-solved-need-some-help-with-php-and-mysql/#findComment-440371 Share on other sites More sharing options...
CSmith1128 Posted January 15, 2008 Author Share Posted January 15, 2008 $dbcnx = mysql_connect("localhost",$mysql_username,$mysql_password) or die("Unable to Connect to the Server at This Time... Please Try Again Later."); Quote Link to comment https://forums.phpfreaks.com/topic/85619-solved-need-some-help-with-php-and-mysql/#findComment-440372 Share on other sites More sharing options...
p2grace Posted January 15, 2008 Share Posted January 15, 2008 Haha woops somehow I missed that. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/85619-solved-need-some-help-with-php-and-mysql/#findComment-440375 Share on other sites More sharing options...
p2grace Posted January 15, 2008 Share Posted January 15, 2008 Do you have phpmyadmin? Does logging in with the username/password you provided work? Quote Link to comment https://forums.phpfreaks.com/topic/85619-solved-need-some-help-with-php-and-mysql/#findComment-440376 Share on other sites More sharing options...
CSmith1128 Posted January 15, 2008 Author Share Posted January 15, 2008 ahh yes... how dumb of me.. i didn't set the permission to access both databases, i only had it set up to access the one Quote Link to comment https://forums.phpfreaks.com/topic/85619-solved-need-some-help-with-php-and-mysql/#findComment-440389 Share on other sites More sharing options...
p2grace Posted January 15, 2008 Share Posted January 15, 2008 Good deal, so does it work then? Quote Link to comment https://forums.phpfreaks.com/topic/85619-solved-need-some-help-with-php-and-mysql/#findComment-440391 Share on other sites More sharing options...
CSmith1128 Posted January 15, 2008 Author Share Posted January 15, 2008 yupp... works great.. Thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/85619-solved-need-some-help-with-php-and-mysql/#findComment-440407 Share on other sites More sharing options...
CSmith1128 Posted January 15, 2008 Author Share Posted January 15, 2008 Yupp! Works great.. Thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/85619-solved-need-some-help-with-php-and-mysql/#findComment-440408 Share on other sites More sharing options...
p2grace Posted January 15, 2008 Share Posted January 15, 2008 Can you click "Topic Solved" then Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/85619-solved-need-some-help-with-php-and-mysql/#findComment-440412 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.