我正在寻找像在 facebook 中一样的类似计数器。我将从数据库中加载带有消息 ID 的各种帖子。我想做点赞(这里是“祈祷”)计数器,它应该在页面后面使用 jquery 和 ajax。我无法获得特定的消息 ID(中)。这里的代码是
jQuery:
$(document).ready(function () {
$("div.pray").click( function()
{
var mid=$(this).val();
$.ajax(
{
type:"POST",
url:"increment.php",
data:'mid='+mid,
success:function ()
{
$("div.pray").text("Prayed");
}
});
});
PHP:
session_start();
if(isset($_SESSION['usrid']))
{
$usr = $_SESSION['usrid'];
include('dbcon.php');
$cot = "select * from posts where userid=$usr LIMIT 10";// order by eventDate DESC, eventHour DESC" LIMIT0,10";
$ex = mysql_query($cot,$con);
while($cont=mysql_fetch_array($ex))
{
$date = date_create($cont['date']);
$mid=$cont['mid'];
echo "<div id='posts'>";
echo $cont['message'];
echo $photo;
echo "<div class='pray'>";
echo "<input type='hidden' class='mid' value='$mid'>";
echo "<a href='#'>Pray</a></div>";
echo "Prayed(".$cont['prayers'].")    ";
echo date_format($date, 'd-m-Y H:i:s');
echo "<hr>";
echo "</div>";
}
}
else
{
echo "Login to see";
}
?>
我只想替换我单击为祈祷的消息,并且它应该加载当前的祈祷数。