Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

How to store friend ids?

Codes here !

Moderators: macek, egami, gesf

How to store friend ids?

Postby billygoatkaraoke » Tue Jul 31, 2012 4:35 am

Gidday

I'm learning basic social networking off the Webintersect demo, in which a user's friend ids are stored in a text column in the format 3, 6, 99, 44 etc, so this is how I've set things up.

To add a friend, the whole array gets loaded into php and the id is added, then the new array string is saved back in mysql. However, I now see that it would be a problem if someone gets added when another transaction is in process.

What is a better way to store friend ids? A simple table with two columns - `your_id` and `friend_id`, so there's a new row for each of your friends?

Thanks for your help.
billygoatkaraoke
New php-forum User
New php-forum User
 
Posts: 91
Joined: Sat Aug 13, 2011 7:20 pm

Re: How to store friend ids?

Postby NigelRen » Wed Aug 01, 2012 11:27 pm

It's better relational design to store the friends as a separate table as you mention. It means that the database can use foreign keys to ensure that your friend really exists ( and not an imaginary friend ) as well as that the friend id your trying to store is actually a number.
NigelRen
php-forum Active User
php-forum Active User
 
Posts: 450
Joined: Fri Aug 05, 2011 9:53 am


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron