【发布时间】:2014-03-01 20:24:08
【问题描述】:
我正在使用脚本为最喜欢的图片投票:http://www.9lessons.info/2009/09/favourite-rating-with-jquery-and-ajax.html
我正在使用两个文件:
<script>
$(document).ready(function()
{
$("span.on_img").mouseover(function ()
{
$(this).addClass("over_img");
});
$("span.on_img").mouseout(function ()
{
$(this).removeClass("over_img");
});
});
$(function() {
$(".love").click(function()
{
var id = $(this).attr("id");
var dataString = 'id='+ id ;
var parent = $(this);
$(this).fadeOut(300);
$.ajax({
type: "POST",
url: "ajax_love.php",
data: dataString,
cache: false,
success: function(html)
{
parent.html(html);
parent.fadeIn(300);
}
});
return false;
});
});
</script>
和
<?php
include("config.php");
$ip=$_SERVER['REMOTE_ADDR'];//client ip address
if($_POST['id'])
{
$id=$_POST['id'];
//IP-address verification
$ip_sql=mysql_query("select ip_add from image_IP where img_id_fk='$id' and ip_add='$ip'");
$count=mysql_num_rows($ip_sql);
if($count==0)
{
// Updateing Love Value
$sql = "update images set love=love+1 where img_id='$id'";
mysql_query( $sql);
// Inserting Client IP-address
$sql_in = "insert into image_IP (ip_add,img_id_fk) values ('$ip','$id')";
mysql_query( $sql_in);
$result=mysql_query("select love from images where img_id='$id'");
$row=mysql_fetch_array($result);
$love=$row['love'];
?>
<span class="on_img" align="left"><?php echo $love; ?></span>
<?php
}
else
{
// Already Loved
echo 'NO !';
}
}
?>
现在,显示每张图片的当前投票数。我愿意
(1) 隐藏此号码并仅处理消息 - 例如#单击此处为这张图片投票/#感谢您的支持
(2) 限制每个用户只能为一张图片投票(现在用户可以为所有图片投票)
不幸的是,我对编码并不是很熟悉,也不知道从哪里开始。任何建议都非常感谢。
谢谢!
【问题讨论】:
标签: javascript php jquery mysql ajax