473,394 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Store Friend relations

bilibytes
128 100+
Hi,

i am trying to figure out how to store a friend relation beetween my users.

1.
I thought about using arrays, store for each user an array containing all its friends. But i don't know if arrays are suported in MySQL:
-> if they weren't i could also do a string which is the result of friends concatenation. But maybe it would be to much work to explode and implode the content at each time a user wants to get a list of its friends.


2.
then i thought about using a simple paired relation:
user1 is friend with user2 and the relation status: -1 for friends, -0 for friendship requested
so table would be:
Expand|Select|Wrap|Line Numbers
  1. user1 | user2 | status
  2. paul  | john  | 0
  3. paul  | ron   | 1
  4. jimi  | paul  | 1
  5.  
ok so when the user requests to be friend of an other one, i insert his name in "user1" and the requested friend in "user2"
Example:
paul asked john to be his friend. -> 0 ->friendship not confirmed yet
paul asked ron to be his friend-> 1 ->friendship confirmed, updated 0->1

This would work fine if:
before i insert a friendship request into the table, i look into "user1" coulumn.

Expand|Select|Wrap|Line Numbers
  1. if(there is a record of the requesting user into user1){
  2.      insert into coulumn user1
  3. }
  4. else{
  5.     insert into column 2
  6. }
this would prevent "friends" table from having the same user name(in fact: id) into the 2 different columns, as i have in the Table example above.
-> john is either on user1 and user2 columns.

THE Question is :
isn't that to much work to perform for a simple friend request insertion?

3.
the other possibility which extends this last one, is not to perform the check at insertion, but then check on select into the two columns:

Example, john wants to see his friends:

Expand|Select|Wrap|Line Numbers
  1. SELECT user1 and user2
  2. FROM friends
  3. WHERE user1 = john OR user2 = john 
  4.  
then i should reorder the resultng array..


Experts, what do you think i should do?

Thankyou very much

bilibytes
Nov 14 '08 #1
0 2597

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Bose | last post by:
Hi I have to make export of SQL Server Database to MS Access and I have done it with the tables but now I need to transfer(export) the relations, keys and indexes. Can any1 tell me how to read...
2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
1
by: Iain | last post by:
I've a fairly complex schema which I'm trying to create a typed data set for. I've had a number of issues to date but it is sort of working (e.g. elements are not considered nullable unless...
1
by: Jef De Rycke | last post by:
Hi access group, I have written code to create relations between tables according to a corresponding relations information table. At first I thought my code was not working properly because...
1
by: Randy Fraser | last post by:
How do I create a relationship on muliple columns in an untyped dataset. Why does this not work. da.Fill(ds) ds.Tables(0).TableName = "DesignSummary" ds.Tables(1).TableName = "FormulaSummary"...
2
by: Joe | last post by:
Hi I am going to receive a dataset downstream and I will not know the the fields number of field relations number of relations So I have to be flexible to take unknown data and be able to...
5
by: G .Net | last post by:
Hi I'm hoping that somebody can help me with a fairly puzzling problem. I've created some DataTables which have relations between them e.g. one to many. In the application, I want to remove...
1
by: ramapriya92 | last post by:
friend : F - Few R - Relations I - In E - Earth N - Never D - Die %%%%%%%%%%%%%%%%%%%% http://padmagirl.blogspot.com %%%%%%%%%%%%%%%%%%%%%
3
by: King | last post by:
This is a new test for object persistency. I am trying to store the relationship between instances externally. It's not working as expected. May be I am doing it in wrong way. Any suggestions? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.