ALTER TABLE dede_archives ADD zan int(11) NOT NULL DEFAULT '0' AFTER weight; |
CREATE TABLE IF NOT EXISTS `dede_zan` ( `id` int(11) NOT NULL AUTO_INCREMENT, `aid` int(11) NOT NULL, `ip` varchar(40) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
function zan($aid){ global $dsql; $row = $dsql->GetOne("Select id,zan From dede_archives where id='".$aid."'"); return $row['zan']; } |
.zan p{background:#000; opacity:.8;filter:alpha(opacity=80);} .zan p a{padding-left:30px; height:24px; background:url(/images/heart.png) no-repeat 4px -1px;color:#fff; font-weight:bold; font-size:14px} .zan p a:hover{background-position:4px -25px;text-decoration:none} |
<script type="text/javascript" src="/jquery.js"></script> $(function(){ $("p a").click(function(){ var zan = $(this); var id = zan.attr("rel"); //对应id zan.fadeOut(300); //渐隐效果 $.ajax({ type:"POST", url:"/zan.php", data:"id="+id, cache:false, //不缓存此页面 success:function(data){ zan.html(data); zan.fadeIn(300); //渐显效果 } }); return false; }); }); |
<div class="zan"><p><a href="#" title="赞一个 "class="img_on" rel="{dede:field.id/}">{dede:field.id function="zan(@me)"/}</a></p></div> |
<?phprequire_once (dirname(__FILE__) . "/include/common.inc.php");$ip =getip(); //获取用户IP $id = $_POST['id']; if(!isset($id) || empty($id)) exit; //查询已赞过的IP$dsql->SetQuery("SELECT ip FROM dede_zan WHERE aid='".$id."' and ip='$ip'");$dsql->Execute();$count = $dsql->GetTotalRow();if($count==0){ //如果没有记录 $dsql->ExecuteNoneQuery("update dede_archives set zan=zan+1 where id='$id'; ");//写入赞数 $dsql->ExecuteNoneQuery("insert into dede_zan (aid,ip) values ('$id','$ip'); ");//写入IP,及被赞的AID $rows = $dsql->GetOne("Select zan from dede_archives where id='".$id."'");//获取被赞的数量 $zan = $rows['zan']; //获取赞数值 echo $zan; }else{ echo "赞过了.."; } |
新闻热点
疑难解答