/    Sign up×
Community /Pin to ProfileBookmark

How You Would INSERT ?

Php Masters!

I need to know how you do things the way you do things.
Let us say, I am building a Social Network (SN).
Let us say, my mysql db looks like this in structure:

Tbl: users;
Columns: id, username, email, friends.

Example:

id|username|email|friends
0|uniqueideaman|uniqueideaman@**.com|ginerjm,nogdog,requinix

Do you see, how I have crunched-up 3 usernames into a single cell ?
Is this how you would do it to list my friends’ usernames ?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@rootJan 08.2018 — Nope.

You would have a friends list where every member link is recorded in a three column table, the first being an auto_increment ID to keep all records sequential and unique, the first ID is the User ID (UID) and the friend is the FID.

ID | UID | FID

1 | 3 | 24

2 | 3 | 399

3 | 55 | 24

4 | 598 | 3

5 | 598 | 55

6 | 6000 | 598

7 | 3 | 598

8 | 24 | 55

9 | 55 | 598

and your relationship can be defined as the users ID pulls a list of ID's of their friends. The table ID is to give a unique ID to allow multiple references of the links between users. In the above example you can see that ID's 1 & 2 have two entries for UID 3 who is linked to friend's FID 24,399 and is also friends with UID 598.

You wouldn't be putting anything other than ID's in the table as this keeps it small and fast and yes, it would appear that you are having multiple links, this list can function as a friends request list as well as your UID without a corresponding FID entry that contains UID could be interpreted as a friend request pending acceptance. This is obviously keeping it very simple.
Copy linkTweet thisAlerts:
@site-developerauthorJan 08.2018 — Nope.

You would have a friends list where every member link is recorded in a three column table, the first being an auto_increment ID to keep all records sequential and unique, the first ID is the User ID (UID) and the friend is the FID.

ID | UID | FID

1 | 3 | 24

2 | 3 | 399

3 | 55 | 24

4 | 598 | 3

5 | 598 | 55

6 | 6000 | 598

7 | 3 | 598

8 | 24 | 55

9 | 55 | 598

and your relationship can be defined as the users ID pulls a list of ID's of their friends. The table ID is to give a unique ID to allow multiple references of the links between users. In the above example you can see that ID's 1 & 2 have two entries for UID 3 who is linked to friend's FID 24,399 and is also friends with UID 598.

You wouldn't be putting anything other than ID's in the table as this keeps it small and fast and yes, it would appear that you are having multiple links, this list can function as a friends request list as well as your UID without a corresponding FID entry that contains UID could be interpreted as a friend request pending acceptance. This is obviously keeping it very simple.[/QUOTE]



Thanks Super Mod, You really a Super Mod.

Pitty this forum does not allow us to give THANKS/REPS.

Anyway, I was told to check these out:

https://en.wikipedia.org/wiki/Fourth_normal_form

https://www.youtube.com/watch?v=UrYLYV7WSHM

Did not bother with the vid as I'm on low bandwidth.

Also, googled:

https://www.google.com/search?q=what+is+4NF+%3F&oq=what+is+4NF+%3F&aqs=chrome..69i57.3945j0j4&sourceid=chrome&ie=UTF-8

And read:

https://www.tutorialcup.com/dbms/fourth-normal-form.htm

Anyway, how would you code the db query to pull-up your friends. Let's say you want to pull-up UID 5's friends.

This is my try using PREP STMNT:

[code=php]
[B]$stmt = mysqli_prepare($conn, "SELECT FID FROM users WHERE UID = ? ");[/B]
[/code]
Copy linkTweet thisAlerts:
@site-developerauthorJan 08.2018 — Nope.

You would have a friends list where every member link is recorded in a three column table, the first being an auto_increment ID to keep all records sequential and unique, the first ID is the User ID (UID) and the friend is the FID.

ID | UID | FID

1 | 3 | 24

2 | 3 | 399

3 | 55 | 24

4 | 598 | 3

5 | 598 | 55

6 | 6000 | 598

7 | 3 | 598

8 | 24 | 55

9 | 55 | 598

and your relationship can be defined as the users ID pulls a list of ID's of their friends. The table ID is to give a unique ID to allow multiple references of the links between users. In the above example you can see that ID's 1 & 2 have two entries for UID 3 who is linked to friend's FID 24,399 and is also friends with UID 598.

You wouldn't be putting anything other than ID's in the table as this keeps it small and fast and yes, [B]it would appear that you are having multiple links,[/B] this list can function as a friends request list as well as your UID without a corresponding FID entry that contains UID could be interpreted as a friend request pending acceptance. This is obviously keeping it very simple.[/QUOTE]


You are correct. It appears that I am having multiple links here. And therefore, I did not originally want to do it this way to save the db getting populated to much (too many entries) to save it from getting bogged down from doing too many tasks. Would not it be less resource using and less querying (hence less traffic to the db) if I do it the way I demonstrated in my original post ?
×

Success!

Help @site-developer spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...