|
uCoz Community Archives Locked Friend Adding System on uCoz |
Friend Adding System on uCoz |
Use PHP!
Code <?php ------>Created By SirDarknight<-------- -- TABLES drop table if exists users; create table users ( user_id int unsigned not null auto_increment primary key, username varbinary(32) unique not null ) engine=innodb; drop table if exists user_friends; create table user_friends ( user_id int unsigned not null, friend_user_id int unsigned not null, created_date datetime not null, primary key (user_id, friend_user_id) -- note clustered composite PK (innodb only) ) engine=innodb; -- TRIGGERS delimiter # create trigger user_friends_before_ins_trig before insert on user_friends for each row begin set new.created_date = now(); end# delimiter ; -- STORED PROCEDURES drop procedure if exists insert_user_friend; delimiter # create procedure insert_user_friend ( in p_user_id int unsigned, -->in p_friend_user_id int<--- unsigned ) proc_main:begin ------>Created By SirDarknight if p_user_id = p_friend_user_id then leave proc_main; end if; insert into user_friends (user_id, friend_user_id) values (p_user_id, p_friend_user_id); end proc_main # delimiter ; drop procedure if exists list_user_friends; delimiter # create procedure list_user_friends ( in p_user_id int unsigned ) proc_main:begin select u.*, uf.created_date, date_format(uf.created_date, '%e-%b-%Y') as created_date_fmt from user_friends uf inner join users u on uf.friend_user_id = u.user_id where uf.user_id = p_user_id order by u.username; end proc_main # delimiter ; -- TEST DATA insert into users (username) values ('f00'),('bar'),('alpha'),('delta'),('omega'),('theta'); call insert_user_friend(1,2); call insert_user_friend(1,3); call insert_user_friend(1,4); call insert_user_friend(1,1); -- oops call insert_user_friend(2,1); call insert_user_friend(2,5); call insert_user_friend(4,1); call insert_user_friend(6,1); -- TESTING (call these sproc from your php !) call list_user_friends(1); See? I Put The Title "Created By SirDarknight" In php quotation. So If You Want To Remove SirDarknight and Put Your Name you need to edit the whole in everywhere. Will Post The Rest Of The Code After uCoz Supports PHP!! Or, If You Want To Get The Whole Code Now Then Added (2011-02-10, 8:12 PM) |
You never closed your PHP tag. That will cause problems if ever it's used. And I think this should belong to User Communication since you never really shown anything the users can do. You just gave a long code without any complete usage information.
Added (2011-02-10, 8:34 PM) "Friends don't let friends use Internet Explorer 6." - Microsoft || Join the cause. Help your friends.
|
I didn't advertise. Did I mention my site url or name?
I just said if they want whole code that are on my site they can join. |
SirDarknight, the section is called "Hints and Tips for uCoz" and not half of the hint and part of the tip. If you want to help - please help. But if you want to advertise - this is not the proper place to do it.
-Moved to Users Communication- |
| |||
| |||