Jump to content

Relationship between two members


phive_

Recommended Posts

Hi all, What I'm trying to do and having a lot of trouble with is pulling how one user is related to another user from my database. I'll explain...

The table (relationships) looks like this:
[table][tr]
[td][table][tr][td][b]ID[/b][/td][/tr][tr][td]type: int[/td][/tr][/table][/td]
[td][table][tr][td][b]RELID1[/b][/td][/tr][tr][td]type: int, is the user id that initiated the relationship request.[/td][/tr][/table][/td]
[td][table][tr][td][b]RELID2[/b][/td][/tr][tr][td]type: int, is the user id of the second person in the relationship.[/td][/tr][/table][/td]
[td][table][tr][td][b]Story[/b][/td][/tr][tr][td]type: varchar(255), quick blerb on how they are related.[/td][/tr][/table][/td]
[td][table][tr][td][b]Type[/b][/td][/tr][tr][td]type: int, a number 1-20 based on the relationship they have[/td][/tr][/table][/td]
[td][table][tr][td][b]Status[/b][/td][/tr][tr][td]type: int, 1 = confirmed by second person, 0 = not confirmed [/td][/tr][/table][/td][/tr][/table]

What i'd like to have pulled is a list of the people that person (for example: 70) is related to. I am having the two following problems:
1. unqid of "70" could be in RELID1 or RELID2 as they could have initiated the request or been the second person.
2. I don't want to display them selves in their own relationship listing

[b]Example Data:[/b]
[table][tr]
[td][table][tr][td][b]ID[/b][/td][/tr][tr][td]1[/td][/tr][tr][td]2[/td][/tr][tr][td]3[/td][/tr][tr][td]4[/td][/tr][/table][/td]
[td][table][tr][td][b]RELID1[/b][/td][/tr][tr][td]25[/td][/tr][tr][td]15[/td][/tr][tr][td]70[/td][/tr][tr][td]12[/td][/tr][/table][/td]
[td][table][tr][td][b]RELID2[/b][/td][/tr][tr][td]54[/td][/tr][tr][td]70[/td][/tr][tr][td]13[/td][/tr][tr][td]8[/td][/tr][/table][/td]
[td][table][tr][td][b]Story[/b][/td][/tr][tr][td]Met on the east coast[/td][/tr][tr][td]Met at walmart[/td][/tr][tr][td]Met walking[/td][/tr][tr][td]Met outside[/td][/tr][/table][/td]
[td][table][tr][td][b]Type[/b][/td][/tr][tr][td]14[/td][/tr][tr][td]11[/td][/tr][tr][td]3[/td][/tr][tr][td]8[/td][/tr][/table][/td]
[td][table][tr][td][b]Status[/b][/td][/tr][tr][td]1[/td][/tr][tr][td]1[/td][/tr][tr][td]1[/td][/tr][tr][td]1[/td][/tr][/table][/td][/tr][/table]

[b]Example Output:[/b]
Again assuming the current user is "70", the sql should pull: 15, 13.. but i'd like to pull their names from another table called "Users" where "15" and "13" are the UnqID's in a column called "ID".
[i]So:[/i]
15 = Bob Smith
13 = Jane DOe

If you have any more questions, or something isn't clear please let me know!

Thanks!
Link to comment
https://forums.phpfreaks.com/topic/29999-relationship-between-two-members/
Share on other sites

ok, after some googling i came up with this statement:

[code]
SELECT RELID1, RELID2, FirstName, LastName
FROM Relationship
INNER JOIN ReMembers
ON Relationship.RELID1 = ReMembers.AccountID
WHERE RELID1 = 69 OR RELID2 = 69
[/code]

However, this only works for RELID1 and not RELID2 column. Moreover, this repeats the data for some reason. ???

Any help anyone can give, would be GREATLY appreciated... And will save me from pulling out all of my hair!

:-[

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.