stewart715 Posted November 8, 2006 Share Posted November 8, 2006 All help is much appreciated :) Thanks.The code below outputs all usernames that have the match shown in $sql (in $row). However, I also need to output a persons uid along with $row. However, I don't know how to combine this:[code]<?php$sql2 = "SELECT buddy FROM buddylist WHERE received = 1 AND uid = 1";$res2 = mysql_query($sql2) or die (mysql_error());while ($row2 = mysql_fetch_row($res2)) { echo "$row2[0]<br />";}?>[/code]WITH THIS:[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 = 1" ;$res = mysql_query($sql) or die (mysql_error());while ($row = mysql_fetch_row($res)) { echo "$row[0]<br />";}?>[/code]SO THAT:[code]<?phpecho $row2[0];echo $row1[0];?>[/code]will output all matches of both like so:2 Mike3 Joe5 Franketc...Any ideas? Please! All help is appreciated :) Quote Link to comment Share on other sites More sharing options...
leeming Posted November 8, 2006 Share Posted November 8, 2006 i dont do my joins the way you do.. urm.. what are the two table names?(buddylist and what?) and fields you wishing to join? Quote Link to comment Share on other sites More sharing options...
stewart715 Posted November 8, 2006 Author Share Posted November 8, 2006 Ok, thanks for your helpI'm trying to get a list of pending friend requests (a pending friendrequest has a value of 1 for received)so example..TABLE: buddylistuid buddy received1 7 13 5 11 8 01 3 1TABLE: usersuid name1 mike7 joe3 john8 billso select select buddy from buddylist where recieved =1 and uid = 1(we'll use 1 for example purposes instead of $user->uid)...then the join will compare the outputted buddy value with uid in users and will output the name that goes along with that user..thats fine..$sql works perfect..however..i need to have a variable that outputs that buddies uid as well..i hope i explained it wellso i'll need the following output (with the example of tables above)[code]<a href="7">Joe</a><a href="3">John</a>[/code] Quote Link to comment Share on other sites More sharing options...
leeming Posted November 8, 2006 Share Posted November 8, 2006 [code]SELECT users.uid, users.name FROM users, buddylist WHERE buddylist.buddy = users.uid AND buddylist.received = '1'[/code]sorry for late reply, got busy fixing my own code ;) Quote Link to comment 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.