1
我有下面的這個程序,做一個簡單的關注/取消關注功能。除了當我刷新頁面時,只有該行中的第一個用戶保留正確的關注/取消關注按鈕,一切都很好。示例我可以關注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>
您指出了我們如何出現意外的行爲,但您沒有提及是否收到任何實際錯誤(即javscript錯誤,PHP錯誤,MySQL錯誤)。你在看你的JavaScript控制檯的錯誤?你有開啓PHP錯誤報告嗎?你有沒有考慮過使用mysql_error()執行MySQL錯誤處理並查看可能會遇到的任何數據庫錯誤?您是否嘗試過在代碼中的關鍵點對'var_dump()'某些變量進行驗證,以驗證您所得到的值是您的期望值?你應該自己採取這些步驟。 –
@mike brant是的,我已經完成了所有這些。沒有MySQL錯誤或php錯誤。值正在被正確拉入。我做了很多工作,把它放在一起,而且我在這一點上陷入困境,因爲我不明白爲什麼第一行會識別行爲而不識別其他行爲。 – Steven