你一直在寻找google pls的好友拖拽分组功能吗?google实现的太帅了!我已经使用PHP和jQuery实现了同样的好友拖拽添加分组的应用。本篇PHP教程就来告诉你如何实现,希望我的示例会对你的社交网站项目有所帮助。
效果如下:
用户表Members
表包含成员(用户)数据,如member_id,member_image等。
sql;">
CREATE TABLE IF NOT EXISTS `members` (
`member_id` int(9) NOT NULL AUTO_INCREMENT,`member_name` varchar(220) NOT NULL,`member_image` text NOT NULL,`dated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,PRIMARY KEY (`member_id`)
);
用户组Groups
sql;">
CREATE TABLE IF NOT EXISTS `groups` (
`group_id` int(9) AUTO_INCREMENT,`group_name` varchar(220),`sort` int(9),`date` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,PRIMARY KEY (`group_id`),KEY `sort` (`sort`)
);
用户组之间的关系User_group
用户和用户租表的关系表user_group包含user_id(memeber_id一样),group_id,member_id()和sort(排序)字段。
sql;">
CREATE TABLE IF NOT EXISTS `user_group` (
`id` int(9) NOT NULL AUTO_INCREMENT,`user_id` int(9) NOT NULL,`group_id` int(9) NOT NULL,`member_id` int(9) NOT NULL,`sort` int(9) NOT NULL,PRIMARY KEY (`id`)
);
Javascript脚本
我们对两个类属性:.members和.group运用拖拽。
groups.PHP
PHP;">
addMembers((int)$_GET['m_id'],(int)$_GET['g_id']);
exit;
}
// Remove Memebers from groups Ajax call
if(isset($_GET['do']))
{
$obj->removeMember($_GET['mid']);
exit;
}
// Reload groups each ajax call
if(isset($_GET['reload'])){ echo $obj->getMembers_reload(); exit; }
if(isset($_GET['reload_groups'])){ echo $obj->getmembergroups_reload(); exit; }
// Initiate Groups and members
$members = $obj->public_members();
$groups = $obj->groups();
?>
Friends
public_members();
if($members)
{
foreach($members as $member)
{
extract($member);
echo "
\n";
echo "\n";
echo "".ucwords($member_name)."\n";
echo "
";
}
}
else
echo "Members not available";
?>
groups();
if($groups)
{
foreach($groups as $group)
{
extract($group);
echo "
\n";
echo ucwords($group_name);
echo "";
echo "";
echo "
";
}
}
?>
- \n";
echo $obj->updateGroups($group_id);
echo "