• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

Some php code

Junior Spellweaver
Joined
Oct 18, 2005
Messages
181
Reaction score
0
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.
 
Custom Title Activated
Loyal Member
Joined
Nov 28, 2004
Messages
2,236
Reaction score
0
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
 
Junior Spellweaver
Joined
Oct 18, 2005
Messages
181
Reaction score
0
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.
 
Custom Title Activated
Loyal Member
Joined
Sep 7, 2004
Messages
1,886
Reaction score
5
Gashek go to hotscripts.com and there should be plenty of CMS of your liking.
 
Divine Celestial
Loyal Member
Joined
Nov 11, 2004
Messages
810
Reaction score
0
I'm sure there're some modules for php/post-nuke that would do that.

[N]asser` ~ Out
 
Junior Spellweaver
Joined
Oct 18, 2005
Messages
181
Reaction score
0
actually, that was LDU cms.
I've found it out few days ago.
 
Custom Title Activated
Loyal Member
Joined
Dec 31, 2004
Messages
4,091
Reaction score
25
PHPNuke is dirty... so many exploits.
 
Divine Celestial
Loyal Member
Joined
Jul 7, 2004
Messages
853
Reaction score
5
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.
I saw on one web site function of "Friends".
There are [My Friends],[Who Added me as Friend], and [People Visited My Profile].
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.

[My Friends] would be handled by a query like this:
Code:
select user,friends from friend_table where user=(PHP inserts username here)
[Who Added me as Friend]
Code:
select user from friend_table where friends like '%(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.
 
Custom Title Activated
Loyal Member
Joined
Aug 8, 2004
Messages
3,892
Reaction score
20
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:
Code:
INSERT INTO crosstable_friends (userID1, userID2) 
VALUES ('this_users_ID', 'friends_users_ID')
. You might want to check wether this connection already exists first by doing this:
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'
- 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.

Now when you want to know who you added as a friend, you perform
Code:
SELECT * 
FROM crosstable_friends 
LEFT JOIN usertable 
  ON userID2 = usertable.userID 
WHERE userID1 = 'this_users_ID'
and to know who added you as a friend you perform
Code:
SELECT * 
FROM crosstable_friends 
LEFT JOIN usertable 
  ON userID1 = usertable.userID 
WHERE userID2 = '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).

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
 
Last edited:
Divine Celestial
Loyal Member
Joined
Jul 7, 2004
Messages
853
Reaction score
5
Thanks for correcting me, my solution was written in ~5 minutes just as a demonstration of what can be done with MySQL.
 
Back
Top