Jump to content

INNER JOIN Help


stewart715

Recommended Posts

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 have

for example purposes lets say $user->uid is 2

TABLE: buddylist
[b]uid  buddy  received[/b]
2      7          1
3      5          1
2      8          0
2      3          1

TABLE: users
[b]uid  name[/b]
2    mike
7      joe
3    john
8      bill

i 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

[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

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.