Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How to output data from friends list
Old 04-28-2008, 05:17 AM How to output data from friends list
drew22299's Avatar
Skilled Talker

Posts: 93
Trades: 0
Hi,

The problem is that sometimes the logged in user will be in friend1 or friend2 depending on who sent the friend request and I want to output only the user that is not the logged in user viewing their friends list.

When a user adds a user as a friend the user who requested the add is inserted into friend2 column, and the other user is inserted into the friend1 coloumn, pending is inserted into the status column.

When the user views their friends list, how can I output the other users usernames and not include the logged in users username in the list as well?

For example, I use this query:

PHP Code:
$query "SELECT * FROM friends_list WHERE friend1='$_SESSION[userid]' and status='confirm' or friend2='$_SESSION[userid]' and status='confirm'"
How can I output only the other user (that is not the logged in user) from the table?

Any ideas?

Last edited by drew22299; 04-28-2008 at 05:18 AM..
drew22299 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-28-2008, 11:45 AM Re: How to output data from friends list
Extreme Talker

Posts: 177
Trades: 0
You could try doing
PHP Code:
$query "SELECT * FROM friends_list WHERE friend1='$_SESSION[userid]' or friend2='$_SESSION[userid]'";
while(
$row mysql_fetch_assoc($query))
{
     if(
$row['status'] == "confirm")
     {
          
code
     
}

that will query all the data where the user logged in has friends, and the while loop iterates through each friend and the if checks to make sure the status is correct.
</span></span>
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Old 04-28-2008, 02:38 PM Re: How to output data from friends list
drew22299's Avatar
Skilled Talker

Posts: 93
Trades: 0
Thanks, but the problem is not getting the data using the mysql query, it's outputting the results, for example, at the moment the friends list looks like this:

(user1 is the logged in user, they should not see their username in their friends list, I want to display just the other users in the friends list)

user1, otheruser
otheruser, user1
user1, otheruser

Any ideas?
drew22299 is offline
Reply With Quote
View Public Profile
 
Old 04-28-2008, 02:53 PM Re: How to output data from friends list
Extreme Talker

Posts: 177
Trades: 0
lets just say there are only 2 columns in the friend table, and 2 people are friends, but the user logged in could be in either column 1 or column 2, and you need to output the opposite one.

What about this?

PHP Code:
if($row['status'] == "confirm")
     {
          if(
$row['friend1'] == $_SESSION['userid'])
          {
                echo 
$row['friend2'];
          }
          elseif(
$row['friend2'] == $_SESSION['userid'])
          {
                echo 
$row['friend1'];
          }
     } 
I think I did this right.

let me know how it works out
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Old 04-28-2008, 03:24 PM Re: How to output data from friends list
drew22299's Avatar
Skilled Talker

Posts: 93
Trades: 0
That looks like it is along the right lines but the output was:

otheruser,
user1(loggedin), other user

I think it is also displaying friends where the status is pending in the elseif, does the following have the correct syntax?

if($row['status'] == "confirm")
{
if(
$row['friend1'] == $_SESSION['userid'
])
{
echo
$row['friend2'
];
}

}

if($row['status'] == "confirm") {

if(
$row['friend2'] == $_SESSION['userid'
])
{
echo
$row['friend1'
];
}
}

}
drew22299 is offline
Reply With Quote
View Public Profile
 
Old 04-28-2008, 04:55 PM Re: How to output data from friends list
Extreme Talker

Posts: 177
Trades: 0
the elseif shouldn't be displaying pending status, cause the first if already checked to make sure status == confirm. I didn't have it in there, but my previous post with the if statements is supposed to be inside the while statement.

with your code, everything seems fine except for the final "}"

Is that the ending of the while loop?
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Old 04-29-2008, 06:47 AM Re: How to output data from friends list
drew22299's Avatar
Skilled Talker

Posts: 93
Trades: 0
I tried the code you gave me again and it worked I forgot to take out the orignial code I was using lol

Thanks,
drew22299 is offline
Reply With Quote
View Public Profile
 
Old 04-29-2008, 10:07 AM Re: How to output data from friends list
Extreme Talker

Posts: 177
Trades: 0
No problem, glad it's working!
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How to output data from friends list
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.49111 seconds with 12 queries