0
我有麻烦实现jquery到我的像按钮脚本。有人可以解释为什么。我对编码相当陌生。谢谢。相关代码如下。 id指收到的项目的ID。jquery/php像按钮问题
<script type="text/javascript">
$('#fav').click(function(e){
$.post('favbuttonchange.php?id=<? echo $id; ?>',
function() {
if($('#fav').hasClass('unfavoritebutton')){
$(this).toggleClass('favoritebutton');
} else {
$(this).toggleClass('unfavoritebutton');
}
e.preventDefault(e);
});
});
</script>
<span class="productlike">
<?php
$favquery1=mysql_query("SELECT fav_id FROM favourites WHERE products_products_id='$id' AND products_users_user_id='$user_id'")or die ("Could not select database because ".mysql_error());
$favcount=mysql_num_rows($favquery1);
if ($favcount == 1){ ?>
<form class='likefav' >
<input id='fav' class='unfavoritebutton' type='submit' name='unfavourite' value=''/>
</form>
<?php }
elseif($favcount == 0) { ?>
<form class='likefav'>
<input id='fav' class='favoritebutton' type='submit' name='favourite' value='' />
</form>
<?php }
?>
</span><br />
那么这里就是我的favbuttonchange.php
$id= (int)strip_tags($_GET['id']);
$favquery1=mysql_query("SELECT fav_id FROM favourites WHERE products_products_id='$id' AND products_users_user_id='$user_id'")or die ("Could not select database because ".mysql_error());
$favcount=mysql_num_rows($favquery1);
if ($favcount == 0){
$favquery2=mysql_query("INSERT INTO favourites (products_products_id, products_users_user_id) VALUES ('$id', '$user_id')")or die ("Could not select database because ".mysql_error());
}
if($favcount ==1) {
$favquery3=mysql_query("DELETE FROM favourites WHERE products_products_id = '$id' AND products_users_user_id = '$user_id'");
}
什么不工作? – ceejayoz 2012-02-28 20:45:44
当我点击最喜欢/不喜欢按钮。它会转到url:product.php?favorite =出于某种原因。没有任何工作,无论是PHP或jQuery。没有jQuery,PHP的工作很好寿 – Anonymous 2012-02-28 20:53:39