Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7932099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:54:50+00:00 2026-06-03T20:54:50+00:00

What i am trying to do is to add a user following system (twitter

  • 0

What i am trying to do is to add a user following system (twitter like) to my script.

This is how the db structure looks like:

CREATE TABLE IF NOT EXISTS `user_follow` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `follower` int(11) NOT NULL,
  `following` int(11) NOT NULL,
  `subscribed` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `follow_unique` (`follower`,`following`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 ;

If i want create i should use this code:

mysql_query(" INSERT INTO `user_follow` (`follower`, `following`, `subscribed`) VALUES ('$follower', '$following', CURRENT_TIMESTAMP); ");

For the unsubscribe it should look like this:

mysql_query(" DELETE FROM `user_follow` WHERE `follower` = '$follower' AND `following` = '$following'; ");

.

$follower = $_SESSION[user_id]; // the user_id for the one who is currently logged id 
$following = $user_id; // the user_id for the user profile where the script will be on

On the profile page i have a form like this:

<?php if (isset($_SESSION[user_id]) && $_SESSION[user_id] != $user_id) { ?>
<form action="" method="post">
<input name="action" type="hidden" value="<?php echo $subscribe_status; ?>"/>
<button name="subject" type="submit" value="<?php echo $subscribe_text.' '.$username; ?>"><?php echo $subscribe_text.' '.$username; ?></button>
</form>
<?php } ?>

What i don’t know is how to link all of those codes…

EDIT:

$subscribe_status should change to follow or unfollow depending if the user is already following that user or not (by checking with a query i think).

Also $subscribe_text should be Follow or Unfollow depending if the currently logged in user ($follower) is already following that user or not.

Can anybody help me please?

EDIT 2 (based on Mihir Singh’s answer)

$user_follow = dbquery(" SELECT * FROM `user_follow` WHERE `follower` = '$follower' AND `following` = '$following'; ");
$check_status = dbrows($user_follow);

$sub = false; //Boolean var which states if subscribed or not

if ( $check_status !== 0 ){ //Pseudo code
    $sub = true; //If row is found, they are subscribed, so set $sub to true
}

if($sub){
     $subscribe_status = "follow";
     $subscribe_text = "Follow";
}

else{
     $subscribe_status = "unfollow";
     $subscribe_text = "Unfollow";
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:54:53+00:00Added an answer on June 3, 2026 at 8:54 pm

    Here’s some code:

    $sub = false; //Boolean var which states if subscribed or not
    
    if (row in table exists --> subscribed ){ //Pseudo code
        $sub = true; //If row is found, they are subscribed, so set $sub to true
    
    if($sub){
         $subscribe_status = "Follow";
         $subscribe_text = "Unfollow";
    }
    
    else{
         $subscribe_status = "Unfollow";
         $subscribe_text = "Follow";
    }
    

    EDIT:

    So, this is the form code that you’re using:

    <?php if (isset($_SESSION[user_id]) && $_SESSION[user_id] != $user_id) { ?>
    <form action="" method="post">
    <input name="action" type="hidden" value="<?php echo $subscribe_status; ?>"/>
    <button name="subject" type="submit" value="<?php echo $subscribe_text.' '.$username; ?>">       
    <?php echo $subscribe_text.' '.$username; ?></button>
    </form>
    <?php } ?>
    

    Based on that, I would change

    <form action="" method="post">
    

    to

    <form action="handler.php" method="post">
    

    and then create a handler file with this:

    <?
        if ($_POST['action'] == "Follow")
            //Perform Unfollow Query to Database
        else
            //Perform Follow Query to Database
    ?>
    

    That’s barebones…. but it should work out. How’s that?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I’m a trying to create a feature where an user an add an
I am trying to create the following scenario... A user logs in by inserting
I am trying to use coleifer/django-relationships to create user relationship system in my site.
Im trying to add a timer to my game so that the user knows
I'm trying to add the distance from the user's position to a selected annotation's
So I'm trying to add some ability to my project to allow user-defined properties
I am currently trying to add a JavaScript confirm message when a user attempts
I'm trying to add a $('body').live('click') listener after the user clicks on a div.
i'm trying to add some navigation arrows which allow the user to go to
I'm trying to add a class (.active) to a text field once the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.