Add friend script

Messages
89
Reaction score
0
Points
6
Hello everyone,

I want to introduce the concept of "adding friends" in my website. But I am not sure about how to start. That is, how I should design the SQL table, algorithm, etc...

Only "friends" will have certain privileges (like posting comments, receiving updates, etc).

Please note that the code will be in PHP.

Looking forward to your tips.

Regards.
 

emoticonllc18

New Member
Messages
5
Reaction score
0
Points
0
Are you a novice PHP programmer. If so I would recommend the following. 1) Download MySQL Workbench from http://www.mysql.com. This will provide you with a visual tool for create the necessary database tables. 2) Install Propel, Phing and Log from PEAR. These software packages will give you a comfortable way of interfacing with the database that you create with MySQL Workbench..

If you are unsure as how to create your database. Consider the following each table must contain an "id" column. This is an automatically incremented numeric column (by MySQL). You will use the "id" column in multiple tables to "relate" records to each other e.g., customers to orders.

If you give me an idea of what your skill level is I can better help you. If this is too technical already I would recommend starting with a PHP CMS like Drupal where you can interactively create what you need and ease yourself into PHP.
 
Last edited:
Messages
89
Reaction score
0
Points
6
No, I am not a novice. I have been coding in PHP for the past 8 months. And I am quite familiar with MySQL and interfacing with databases.

Actually, I am trying to create a social networking site of my own from scratch; like Facebook or Twitter. And I wanted know about designing the friends part of the database. That is, what columns (e.g.: userID, friendID, relationID) I should create, etc. And how it would affect their privileges (like 'commenting', 'getting notifications').
Later, I would also introduce friend groups and other related aspects. So I need to design this particular part of the database now, so as to avoid problems in the future.

I hope that you have now understood my question. Do let me know if something is not clear.

Looking forward to your answer.
 

divinemamgai70

New Member
Messages
2
Reaction score
1
Points
0
Hi buddy, I think you should use PHP, Ajax and somewhat Javascript for this purpose. And not to mention, you had to have some knowledge about MySQL because it is the prime code for this purpose. I think you need some tutorials to begin with, so here is a simple link.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Add another table, friendships. Two columns member_id and friend_id where member_id is the one who made friend_id a friend. Primary index on the combination of the two cols. Index on each column too.

If member 223 wants to comment on member 456, you check to see if you have an entry with member_id=456 and friend_id= 223 . That is, if you want only friends to comment (or do X). If you want the user to decide (ie anybody can comment, only friends, nobody) you would have to check with your user table first.
 
Messages
89
Reaction score
0
Points
6
I did not understand this part:

Primary index on the combination of the two cols. Index on each column too.

What do you mean by "primary index on the combination"?

Thanks for your inputs, by the way.

---------- Post added at 06:19 PM ---------- Previous post was at 06:17 PM ----------

Hi buddy, I think you should use PHP, Ajax and somewhat Javascript for this purpose. And not to mention, you had to have some knowledge about MySQL because it is the prime code for this purpose. I think you need some tutorials to begin with, so here is a simple link.

I shall be using Ajax after having constructed a basic version of my website.
Thanks for the info source, though.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
You use a clause: PRIMARY KEY (member_id, friend_id) in your table definition.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Experience isn't solely a matter of time; quality of experience counts for much. What's your understanding of the relational model? It's crucial in modeling objects in the solution domain.

The first step in any development project is to define the problem (is friendship a symmetric relationship? Does friendship confer anything else other than special privileges? &c.). Then define the requirements to keep you on-track, so you know that, when you've finished, you've met your goals. Behavior driven development can also help you to keep focus.
 

emoticonllc18

New Member
Messages
5
Reaction score
0
Points
0
If you are wanting to get up and running quickly consider installing Word Press from http://www.wordpress.org. It is a PHP / MySQL driven application that is a perfect example of what you are trying to accomplish. Just review the source code. You know PHP. Word Press is not a complicated database schema so you should be okay. Otherwise, you need to start with the database design basics-- here is a good tutorial: http://www.databaseprimer.com/relationship_1tox.html
 

theone48

New Member
Messages
237
Reaction score
7
Points
0
Can't things be done any easier? Why don't you guys just give him the code to put in, or whatever it is? You tell him where to put it and he's all ready to go. Can't get any easier than that. He might understand the thing better if he saw it, too.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Because:
  • Answers that simply give teh codez aren't actually helpful. Answer seekers must develop the skills to write the code themselves. Unless you're familiar enough with programming and development, it's hard to learn the proper concepts & abstractions from reading code. If you are familiar enough, you likely don't need code. It's far better to teach someone to fish than to give them a fish.
  • The requirements aren't specific enough to write any code.
  • It's extremely unlikely that any posted code could work without alteration, since it must interact with the OP's current code base.
  • The OP asked for tips, not a complete solution.

Code may accompany an explanation as an illustration, but that's about as far as it can usefully go.
 

theone48

New Member
Messages
237
Reaction score
7
Points
0
That implies if I wanted to program a really cool site, I'd have to learn programming first. From scratch. :frown: For someone who knows more about m theory than c++, that sounds too far-fetched. So many progs, so many types of langs, so many commands and definitions. There's got to be an easier way and still be able to have something self-done.
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
There's got to be an easier way and still be able to have something self-done.

Not really, and that's why there's a market for shrinkwrapped software (and why there are open-source projects, etc.). And there are open-source "social networks". The problem is that they are either too vast or too narrow in scope, and will rarely be exactly what you need. They're either going to cover every possible dream and desire, or they're going to be missing features.

Only you really know what you need, and there is no general-purpose solution to a sui generis problem. The problem has to be properly defined before a solution can be found. In a case like this, that means defining what "friend" means, and what relationship it implies. Keep in mind that we're talking about sharing data. Are all friendships equal? Or should there be more or less restrictive sharing relationships?

For the most part, coding anything more involved than a blog about cats is a matter of defining and structuring the data and the security around it -- who should be able to read what, who can modify it when, how do the different chunks of data interact and intertwine. That's really the "hard part" of coding a website or application. Turning your data into HTML according to the rules you establish is really pretty easy -- I can teach anybody of average intelligence and who is motivated enough about PHP to build a site in a day or two, and getting it from a book (if you do the exercises) is almost as fast. Doing a slick, AJAX-y front end is only a little more effort -- it involves learning both CSS and JavaScript, although something like jQuery or YUI makes that a lot easier than it used to be. But if the data structure is wrong, no amount of code can make it right.

Programming -- expressing a procedure in a formal, restricted, artificial language -- is really a lot easier than most people think it's going to be. It's getting a good mental picture of what the procedure is that's hard. And it really doesn't matter how big the bricks are if you don't know what the house is supposed to look like, so even if there were a simple drag-and-drop, picture-based coding environment that you could use, it wouldn't make any difference if you can't really explain the details of what you want to do. If you can explain the details, then it's usually pretty darned easy to translate that into a high-level programming language like PHP.
 

theone48

New Member
Messages
237
Reaction score
7
Points
0
Maybe so but I wouldn't know. I'm used to the shrinkwrapped methods. By the way, is PHP top programming language of choice now? There are so many of them, I've lost track.
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
Actually, PHP is something that most "elite" programmers look down upon in scorn. And, to an extent, they have a point. PHP started off as something very small, and sort of grew organically over the years. Some parts are maddeningly inconsistent, though there are plans afoot to eliminate that over the next few releases. Data typing is both dynamic and weak, so it's nearly impossible to prove that a program is correct. And there's no good way to separate the layers* (the data layer, the "rules" layer and the HTML).

That said, PHP is ubiquitous -- it's really, really hard to find a web hosting provider that doesn't support PHP and MySQL. It doesn't matter how snobbish you want to be about programming languages or database ACID compliance if deploying a site is going to cost more than you can reasonably afford. Want to do Ruby on Rails? Well, a Heroku instance starts at about $US50/month. Haskell? Racket? Common Lisp? You'll need a VPS of some sort for them. Scala? Clojure? Java-based hosting isn't free either. Python? You'll probably end up going beyond the free quota on the Google AppEngine quickly, especially on the datastore side. All of those are arguably "better" languages. All of them are excellent choices for creating a business ready to take over the world, especially when they're combined with a database that can shard, replicate and scale. And none of them will let you run a site on a host that charges four bucks a month all in, let alone run to any real size for free.

PHP is incredibly easy to learn. That's one of the things that has led to its poor reputation -- like Visual Basic on Windows, the bar to entry is very low, so there is an abundance of horrible code out there, cut-and-pasted from equally horrid "tutorials" by people who never took the time to learn what they were doing. (Many of the tutorial writers seem not to have taken the time either, for that matter.) And a lot of the best-known open source PHP projects should have been rewritten years ago rather than just having more and more features added.

Just because you can write bad code in PHP, though, doesn't mean you have to. It really isn't hard to do it right. You can start getting your feet wet on your own machine (if you're a Windows user, then WampServer or XAMPP is just a download away -- the "AMP" is Apache, MySQL and PHP). Misson has pointed to a lot of excellent tutorials (and given good reasons for staying far away from others). The PHP documentation is pretty darned good as these things go (second, in my opinion, only to the programmer documentation for Lotus Notes and Domino). And there's always plenty of help here (and elsewhere) if you're willing to learn.
_________
* There are ORMs (object/relational managers) and templating engines available for PHP that are intended to let you separate the layers, but they drastically reduce efficiency while providing only a modest reduction in complexity. They're great for what they're great for -- but that doesn't include trying to run a site on the cheap.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
That implies if I wanted to program a really cool site, I'd have to learn programming first. From scratch.
Point 1 addresses requests for programming help, while points 2-4 specifically address the OP's post, not running websites in general. Thus the post doesn't imply programming knowledge is required in general to build a site. Since the OP already has a custom code base, anything that's tightly coupled to existing structure must be highly customized, which means he will need to do a fair bit of programming.

However, if you want to program anything, by definition you'll need to know how to program.

So many progs, so many types of langs, so many commands and definitions.
You only need one.
 
Top