stewart715 Posted November 7, 2006 Share Posted November 7, 2006 I can't seem to figure this out whatsoever! Any help will be much appreciated. To explain best, I'll show you the database tables I havefor example purposes lets say $user->uid is 2TABLE: buddylist[b]uid buddy received[/b]2 7 13 5 12 8 02 3 1TABLE: users[b]uid name[/b]2 mike7 joe3 john8 billi need a code that will select buddy from buddylist where $user->uid = uid and receieved = 1 and then check users where the outputted buddy number = uid (in users) then to output the name..so joe and john should come out..it will see that $user->uid (2) has 7 and 3 next to it in buddy where recieved is 1...then it will find that persons name by comparing 7 and 3 to uid in users and then ouput joe and john..im guessing its an innerjoin? Thanks for ANY help! Link to comment https://forums.phpfreaks.com/topic/26486-inner-join-help/ Share on other sites More sharing options...
stewart715 Posted November 7, 2006 Author Share Posted November 7, 2006 Also, I can't seem to find any tutorials on this Link to comment https://forums.phpfreaks.com/topic/26486-inner-join-help/#findComment-121164 Share on other sites More sharing options...
kirk112 Posted November 7, 2006 Share Posted November 7, 2006 Something like this?SELECT b.buddy, u.users FROM buddylist as b LEFT JOIN users AS u ON b.buddy = u.uid WHERE b.uid = '2' AND b.received = '1'Not sure if that is what you where looking for (untested) Link to comment https://forums.phpfreaks.com/topic/26486-inner-join-help/#findComment-121189 Share on other sites More sharing options...
stewart715 Posted November 7, 2006 Author Share Posted November 7, 2006 Yes kind of but i need it to output 'name' from users Thank you Link to comment https://forums.phpfreaks.com/topic/26486-inner-join-help/#findComment-121196 Share on other sites More sharing options...
stewart715 Posted November 7, 2006 Author Share Posted November 7, 2006 Also, I'm not sure how to have it make a list of everything..I know mysql_result would give me just one of the nameshow could I make it list the matches? Well, I guess first I need the query code lol. I've been working on this for so long and I can't get it. Link to comment https://forums.phpfreaks.com/topic/26486-inner-join-help/#findComment-121200 Share on other sites More sharing options...
Barand Posted November 7, 2006 Share Posted November 7, 2006 try[code]SELECT u.nameFROM buddylist bINNER JOIN users u ON b.buddy = u.uidWHERE b.received = 1AND b.uid = 2[/code] Link to comment https://forums.phpfreaks.com/topic/26486-inner-join-help/#findComment-121260 Share on other sites More sharing options...
stewart715 Posted November 7, 2006 Author Share Posted November 7, 2006 Fantastic. Thank you very much (:Now, what would I do to list the results?mysql_result doesn't work... Link to comment https://forums.phpfreaks.com/topic/26486-inner-join-help/#findComment-121263 Share on other sites More sharing options...
Barand Posted November 7, 2006 Share Posted November 7, 2006 [code]<?php$sql = "SELECT u.name FROM buddylist b INNER JOIN users u ON b.buddy = u.uid WHERE b.received = 1 AND b.uid = 2" ;$res = mysql_query($sql) or die (mysql_error());while ($row = mysql_fetch_row($res)) { echo $row[0] . '<br />';}?>[/code] Link to comment https://forums.phpfreaks.com/topic/26486-inner-join-help/#findComment-121267 Share on other sites More sharing options...
stewart715 Posted November 7, 2006 Author Share Posted November 7, 2006 Edit. nevermind! thats perfect thanks so much! Link to comment https://forums.phpfreaks.com/topic/26486-inner-join-help/#findComment-121269 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.