dqan70724 2017-07-09 09:28
浏览 48
已采纳

结果与我预期的不一样

Now I want to make unfollow button if some one already followed then don't show follow button the browser should be show unfollow button instead of follow button like twitter. I just tested (Unfollow button is appear) there but not working perfectly . it because when i online from (user1) and follow some one it work and follow button changed to unfollow but when i online from (user2) , want to follow same person which followed by (user1) .. From (user2) timeline it showing already followed(Button) please check the code

if(isset($_POST['follow']))
        {
            $checkFollow=mysqli_query($con,"SELECT follower_id FROM follower WHERE user_id='$userid'");

            if(mysqli_num_rows($checkFollow)==0)
            {
                $follow=mysqli_query($con,"INSERT INTO follower(user_id,follower_id) VALUES ('$userid','$followerid')");
                echo "You Followed";
            }
            else
            {
                echo "Sorry! You already followed this profile";
            }
            $isFollowing=True;
        }

        $checkFollow=mysqli_query($con,"SELECT follower_id FROM follower WHERE user_id='$userid'");
        if(mysqli_num_rows($checkFollow))
        {
            $isFollowing=True;
        }

    }

HTML Code is

  <form action="<?php echo $username;?>" method="post">                              
                       <?php
                             if($isFollowing)
                             {
                             echo "<input type='submit' value='Unfollow' name='unfollow' class='unfollow_button'>";
                             }
                             else
                             {
                                echo "<input type='submit' value='Follow' name='follow' class='unfollow_button'>"; 
                             }

                             ?>
                         </form>
  • 写回答

1条回答 默认 最新

  • dtftao7249656 2017-07-09 10:04
    关注

    I tried guessing your database structure based on your initial code and put up this answer:

    if(isset($_POST['follow']))
    {
        $id = $_GET['id'];
        $user_query = mysqli_query($con,"SELECT id FROM user_reg WHERE user_name='$id'");  // ($id) is actually $_GET variable
    
        if(mysqli_num_rows($user_query) > 0) { //make sure you have at least one result for that $id
            $row = mysqli_fetch_assoc($user_query); //fetch the database result
            $userid = $row['id']; //assign the value to the $userId variable
        } else { // die if no user found with that $id
            die("User id not found");
        }
    
        $followerid=$idd;  // ($idd) is current session (User Logged in)
        $checkFollow=mysqli_query($con,"SELECT follower_id FROM follower WHERE user_id='$userid'");
    
        if(mysqli_num_rows($checkFollow) == 0) //check if no rows resulted in the $checkFollow query
        {
            //VERY IMPORTANT!!! make sure the column names are correct. You were using follower_id and user_id in the $checkfollow query and the followerid and userid in the INSERT query
            $follow=mysqli_query($con,"INSERT INTO follower (user_id,follower_id) VALUES ('$userid','$followerid')"); 
            echo "Followed";
        }
        else
        {
            die("User already followed");
        }
    }
    
    
    ?>
    
    <form action="test.php?id=<?php echo $username;?>" method="post">
        <input type="submit" value="Follow" name="follow" class="follow_button">
    </form>
    

    I hope this helps

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程