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

Posts: 88
Location: Wiltshire, UK
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?
__________________
www.hotlista.co.uk

Last edited by drew22299 : 04-28-2008 at 04:18 AM.
drew22299 is offline
Reply With Quote
View Public Profile Visit drew22299's homepage!
 
When You Register, These Ads Go Away!
     
Old 04-28-2008, 10:45 AM Re: How to output data from friends list
Skilled Talker

Posts: 92
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, 01:38 PM Re: How to output data from friends list
drew22299's Avatar
Skilled Talker

Posts: 88
Location: Wiltshire, UK
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?
__________________
www.hotlista.co.uk
drew22299 is offline
Reply With Quote
View Public Profile Visit drew22299's homepage!
 
Old 04-28-2008, 01:53 PM Re: How to output data from friends list
Skilled Talker

Posts: 92
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, 02:24 PM Re: How to output data from friends list
drew22299's Avatar
Skilled Talker

Posts: 88
Location: Wiltshire, UK
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'
];
}
}

}
__________________
www.hotlista.co.uk
drew22299 is offline
Reply With Quote
View Public Profile Visit drew22299's homepage!
 
Old 04-28-2008, 03:55 PM Re: How to output data from friends list
Skilled Talker

Posts: 92
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, 05:47 AM Re: How to output data from friends list
drew22299's Avatar
Skilled Talker

Posts: 88
Location: Wiltshire, UK
I tried the code you gave me again and it worked I forgot to take out the orignial code I was using lol

Thanks,
__________________
www.hotlista.co.uk
drew22299 is offline
Reply With Quote
View Public Profile Visit drew22299's homepage!
 
Old 04-29-2008, 09:07 AM Re: How to output data from friends list
Skilled Talker

Posts: 92
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

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

vB 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.15269 seconds with 13 queries