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 :)
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.