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 :) Link to comment https://forums.phpfreaks.com/topic/26522-creating-2-variables-from-2-queriesi-dont-see-my-other-posthm/ 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? Link to comment https://forums.phpfreaks.com/topic/26522-creating-2-variables-from-2-queriesi-dont-see-my-other-posthm/#findComment-121344 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] Link to comment https://forums.phpfreaks.com/topic/26522-creating-2-variables-from-2-queriesi-dont-see-my-other-posthm/#findComment-121345 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 ;) Link to comment https://forums.phpfreaks.com/topic/26522-creating-2-variables-from-2-queriesi-dont-see-my-other-posthm/#findComment-121368 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.