Jump to content

Creating 2 Variables from 2 queries..i dont see my other post..hm


stewart715

Recommended Posts

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]<?php
echo $row2[0];
echo $row1[0];
?>[/code]
will output all matches of both like so:
2 Mike
3 Joe
5 Frank
etc...
Any ideas? Please! All help is appreciated :)
Ok, thanks for your help

I'm trying to get a list of pending friend requests (a pending friendrequest has a value of 1 for received)
so example..

TABLE: buddylist
uid  buddy  received
1      7          1
3      5          1
1      8          0
1      3          1

TABLE: users
uid  name
1    mike
7      joe
3    john
8      bill

so 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 well

so i'll need the following output (with the example of tables above)
[code]<a href="7">Joe</a>
<a href="3">John</a>
[/code]

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.