问题描述
|
我想使用PHP和MysqL创建一个“关注用户”系统。我正在开发一个需要此功能的网站,并希望在脚本编码和表结构方面获得一些帮助-我被困住了。
我希望user1能够“跟随” user2而不必确认友谊。用户1单击“关注按钮”后,我希望收到一条通知,通知用户2已将用户1添加到他们的朋友中。这只是我希望网站功能的第一部分,但这对我有很大帮助。
解决方法
非常“低级”的简化答案(从很容易的意义上讲-因此并不是经过实际测试的; p)
表“ 0”的结构可能类似于:
followerUserID-pk;想要关注“ 1”的用户的用户标识
followingUserID-pk;后面跟着“ 2”的用户的用户标识
时间戳-可用于跟踪
followerUserID
添加followingUserID
的时间
php代码(如前所述:非常简化)
<?php
// ...
class UserRelation extends User {
/**
* follow userID $userID and tell $userID that someone follows him
*
* @param int $userID
* @return void
**/
public function followUserID($userID) {
// send a message that $this->userID follows $userID
Message::sendFollowUserNotification($this->userID,$userID);
// add to database
$this->setFollowingUser($userID);
}
/**
* adds it to database
*
* @param int $userID
* @return void
**/
private function setFollowingUser($userID) {
// write to database
Database::executeQuery(\"INSERT INTO user_following(followerUserID,followingUserID) VALUES (\". $this->userID .\",\". $userID .\");
}
}
// ...
?>
如果您需要进一步的帮助,请更加具体-我只可以向您展示一个基本示例。该主题过于复杂,无法在10分钟内解释。