sean04 Posted April 5, 2010 Share Posted April 5, 2010 Hey guys, so I have 2 tables... user_detail ID Email Country 1 [email protected] 1 country ID Country 1 Canada 2 States How can I write a query so when I call a variable to get my country it gets "Canada" instead of "1" Thanks! Link to comment https://forums.phpfreaks.com/topic/197649-grab-data-from-2-tables/ Share on other sites More sharing options...
ignace Posted April 5, 2010 Share Posted April 5, 2010 SELECT u.email, c.country FROM user_detail u JOIN country c ON u.country = c.id Link to comment https://forums.phpfreaks.com/topic/197649-grab-data-from-2-tables/#findComment-1037317 Share on other sites More sharing options...
sean04 Posted April 5, 2010 Author Share Posted April 5, 2010 Thanks for the reply! I get this error: Resource id #10 I want to call the results from another page... Like a profile page of that user. $loggedUserCountry = mysql_query("SELECT u.User_ID, c.Country_Description FROM user_detail u JOIN country c ON u.Country = c.ID WHERE User_ID = 'logged[user_ID]'"); Then on the profile page I do this Country: $loggedUserCountry Link to comment https://forums.phpfreaks.com/topic/197649-grab-data-from-2-tables/#findComment-1037432 Share on other sites More sharing options...
GoneNowBye Posted April 5, 2010 Share Posted April 5, 2010 you could also use a nested slelect select id,email,(select country from country where country.id = user_detail.id) as country from user_detail i find that easier Link to comment https://forums.phpfreaks.com/topic/197649-grab-data-from-2-tables/#findComment-1037454 Share on other sites More sharing options...
sean04 Posted April 5, 2010 Author Share Posted April 5, 2010 Thanks! How would I go about putting in $logged[user_ID] which is the User_ID of the current logged in individual so I can get there country? Link to comment https://forums.phpfreaks.com/topic/197649-grab-data-from-2-tables/#findComment-1037461 Share on other sites More sharing options...
sean04 Posted April 7, 2010 Author Share Posted April 7, 2010 Could someone please give me a hand. $logged[user_ID]; is the user id of the current logged in user. How would I go about writing this query and get the country for a specific user? Link to comment https://forums.phpfreaks.com/topic/197649-grab-data-from-2-tables/#findComment-1038351 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.