I'm trying to make some good-looking site. I saw on one web site function of "Friends".
There are [My Friends],[Who Added me as Friend], and [People Visited My Profile].
Can someone tell me the way how to do that? Thanx.
Printable View
I'm trying to make some good-looking site. I saw on one web site function of "Friends".
There are [My Friends],[Who Added me as Friend], and [People Visited My Profile].
Can someone tell me the way how to do that? Thanx.
well, most of forums has got such a feature (or used with hack).
if you need to add such a feat to your site by yourself you need to log somewhere users, user actions, etc. I suggest using any content management systems that have such a feat, cuz it's not so easy to make what you want
Well, I didn't find such cms with the features I wrote. If you wanna see what I ment, please contact me by pm, and I'll be more then happy to show you.
Thanx.
Gashek go to hotscripts.com and there should be plenty of CMS of your liking.
I'm sure there're some modules for php/post-nuke that would do that.
[N]asser` ~ Out
actually, that was LDU cms.
I've found it out few days ago.
PHPNuke is dirty... so many exploits.
You need a database to store the information.
The PHP only interfaces with the database.
It's not hard, just write it yourself... officially "started" writing PHP several days ago with NO prior knowledge or experience, and have written most of an account management system already.
The easiest way would be a database table containing one row for each user of your site; one column would be the username and another column would be a varchar or some string datatype that can contain a comma-delimited list of the usernames of the friends.Quote:
I saw on one web site function of "Friends".
There are [My Friends],[Who Added me as Friend], and [People Visited My Profile].
[My Friends] would be handled by a query like this:
[Who Added me as Friend]Code:select user,friends from friend_table where user=(PHP inserts username here)
For the "people visited..." you'd do something similar, only you'd need to store and use from the database information about user visits via cookies.Code:select user from friend_table where friends like '%(PHP inserts username here)%'
You know you may get much gay love from me username1, but this time I have to correct you I'm affraid. A comma seperated list is definately not the way to go here.
I would suggest making a cross-link table, with 2 columns: userID1 and userID2. Each time someone adds someone else as a friend, you insert a new row with the first users ID in column 1 and the second users ID in column 2 or vice versa. This will look something like this:. You might want to check wether this connection already exists first by doing this:Code:INSERT INTO crosstable_friends (userID1, userID2)
VALUES ('this_users_ID', 'friends_users_ID')
- if the result is bigger then 0 you don't perform the insert query. This can also be fitted into 1 query, but if I'm going to just write that out chances are good I make a mistake since conditional insert queries tend to be a bit tricky. Best to fiddle around with it yourself.Code:SELECT COUNT(*)
FROM crosstable_friends
WHERE userID1 = 'this_users_ID'
AND userID2 = 'friends_users_ID'
OR WHERE userID1 = 'friends_users_ID'
AND userID2 = 'this_users_ID'
Now when you want to know who you added as a friend, you performand to know who added you as a friend you performCode:SELECT *
FROM crosstable_friends
LEFT JOIN usertable
ON userID2 = usertable.userID
WHERE userID1 = 'this_users_ID'
(note that both queries can be made into one single query that selects all your friends, but I'd like to have the extra data available).Code:SELECT *
FROM crosstable_friends
LEFT JOIN usertable
ON userID1 = usertable.userID
WHERE userID2 = 'this_users_ID'
This is much faster then username1's solution because you don't have to do a full-text search over an entire table. It is also much smaller because all you store are integers, which are a lot smaller then character strings :)
Optionally you can store addition information, like when the friends connection was made, or wether it was accepted, in additional columns. This is quite easy once you get the main idea. Again, I suggest you fiddle around with it a bit :smile:
And yes, this does require one to know a bit of PHP coding. If you do not, I suggest you read my guide here
Thanks for correcting me, my solution was written in ~5 minutes just as a demonstration of what can be done with MySQL.