How to follow and unfollow users? With following code, list of users appears. containing link to action.php
If not following anyone goto action.php to follow that user from list or if following then show link for unfollow
How to check from table following
condition check:
if ($following)
{
<a href='action.php?id=$uid&do=unfollow'>unfollow</a>";
}
else{
echo "<a href='action.php?id=$uid&do=follow'>follow</a>";
}
***
CREATE TABLE IF NOT EXISTS `members` (
`member_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`firstname` varchar(100) DEFAULT NULL,
`lastname` varchar(100) DEFAULT NULL,
`login` varchar(100) NOT NULL DEFAULT '',
`passwd` varchar(32) NOT NULL DEFAULT '',
`friends` text NOT NULL,
PRIMARY KEY (`member_id`)
)
CREATE TABLE `following` (
`user_id` INT NOT NULL ,
`follower_id` INT NOT NULL ,
PRIMARY KEY ( `user_id` , `follower_id` )
)
$user_id=$_SESSION['SESS_MEMBER_ID']; //user logged in
$sql = "select * from members where member_id != $user_id order by firstname";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result))
{
$uid=$row["member_id"];
$fullname= $row["firstname"]." ".$row["lastname"];
echo "$fullname <small><a href='action.php?id=$uid&do=follow'>follow</a></small> <br />"; // follow or unfollow
}