• Page 1 of 1
  • 1
Friend Adding System on uCoz
SirDarknight
Posts: 247
Reputation: -5

Message # 1 | 2:12 AM
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 Can Use Icon On The Place Of "Adding Friends" Too.

CoffeeCone
Posts: 687
Reputation: 41

Message # 2 | 2:34 AM
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)
---------------------------------------------
And also, stop advertising your website. People will join if they want. You can create a dedicated thread for your site instead of plugging it into each and every thread that you make.


"Friends don't let friends use Internet Explorer 6." - Microsoft || Join the cause. Help your friends.


SirDarknight
Posts: 247
Reputation: -5

Message # 3 | 2:41 AM
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.

Natashko
Posts: 3366
Reputation: 171

Message # 4 | 12:40 PM
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-
  • Page 1 of 1
  • 1
Search: