关注/取消关注按钮问题

时间:2013-01-11 20:56:13

标签: php jquery mysql

我在下面有这个程序,它有一个简单的跟随/取消跟踪功能。一切都很好,除了当我刷新页面时,只有行中的第一个用户保留正确的关注/取消关注按钮。示例我可以关注user1 user2和user3,但是当我刷新时,user1仍然表示FOllOWING。不确定是什么问题,也许有人可以发现代码中的缺陷。谢谢。

<!DOCTYPE html> 
<html> 
    <head> 


        <link rel="stylesheet" href="style.css" type="text/css" media="screen"/> 
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
        <script type="text/javascript" src="jquery.livequery.js"></script>

        <script type="text/javascript"> 
           $(document).ready(function() { 

                    $('.buttons > a').livequery("click",function(e){

                        var parent  = $(this).parent();
                        var getID   =  parent.attr('id').replace('button_','');

                        $.post("follow.php?id="+getID, {

                        }, function(response){

                            $('#button_'+getID).html($(response).fadeIn('slow'));
                        });
                }); 
            });
        </script>
    </head> 

    <body> 

    <br clear="all" />

        <div id="content"> 

        <br clear="all" />
        <br clear="all" />
        <?php  



        $test = $fgmembersite-> UserID();

            $userip = $_SERVER['REMOTE_ADDR'];

            $result = mysql_query("SELECT fgusers.*, tblimage.* FROM fgusers LEFT JOIN tblimage ON tblimage.userid = fgusers.id_user");

            while ($row = mysql_fetch_array($result))
            {?>
                <div class="digg-panel">

                    <div class="img-username">

                        <img alt="<?php  echo $row['username']?>" src="<?php  echo $row['photo']?>.png" width="40" height="40" class="userImage" alt="" />
                        <div class="user-title">
                            <a href="http://digg.com/<?php  echo $row['username']?>" class="fullname"><?php  echo $row['name']?></a>

                            <a href="http://digg.com/<?php  echo $row['username']?>" class="username"><?php  echo $row['username']?></a>
                        </div>
                    </div>

                    <?php
                    $res = mysql_query("select * from tblfollowers where follower_id = '$test' AND username = ".$row['id']);

                    $check_result = @mysql_num_rows(@$res);

                    if($check_result > 0)
                    {?>
                        <span class="buttons" id="button_<?php echo $row['id_user']?>"><a class="btn-following" href="javascript: void(0)"></a></span>
                        <?php
                    }
                    else
                    {?>
                        <span class="buttons" id="button_<?php echo $row['id_user']?>"><a class="btn-follow" href="javascript:void(0)"></a></span>
                        <?php
                    }?>
                    <br clear="all" />

                    <div class="bio">
                    <?php  echo $row['email']?>
                    </div>

                </div>
            <?php  
            }?>






        </div> 


        <br clear="all" />

    </body> 
</html>

1 个答案:

答案 0 :(得分:0)

如果你可以像下面那样实施你的click event。可能你的问题会解决。试试吧。

$('.buttons > a').expire("click").livequery("click",function(e){

});

有关详细信息,请查看jQuery Live Query Plugin Documentation

我希望这会对你有所帮助。