您好,欢迎访问一九零五行业门户网

php+mysql+ajax点赞和踩的功能

嫌麻烦的也可以:点击下载
html:
给力 {ovov:$answer_datas.goods/} 不给力 {ovov:$answer_datas.bads/}
html对应的php文件
$value){ if($value['uid']==$uid){ $zan_lists[]=$value['answer_id']; } } $smarty->assign('zan_list',$zan_lists);//查询当前登录的会员的uid对应的点赞的回答 /*****赞结束****/ /*****踩开始****/ $cai_list = json_decode(str_replace(','',$cai_json),true); $cai_lists=array(); foreach($cai_list as $key=>$value){ if($value['uid']==$uid){ $cai_lists[]=$value['answer_id']; } } $smarty->assign('cai_list',$cai_lists);//查询当前登录的会员的uid对应的踩的回答 /*****踩结束****/ $smarty->display('自己的静态页面'); exit(); break;}?>
ajax文件:
errormsg('文件错误:shuzu/ovovsys_zan.php 不存在!');exit(); } //将指定的数组转换成json数据,并且将双引号转换成单引号,不然放到数组文件中后会出错----4 $zan_new_json = str_replace('',',json_encode($zan_array)); $fp = @fopen($config_path,'r+'); if(!$content = @fread($fp,filesize($config_path))){ $base->errormsg('无法读取shuzu/ovovsys_zan.php文件!');exit(); } //执行替换,将数组文件中对应的json数据----5 $content = str_replace(\$zan_json = \{$zan_json}\,\$zan_json = \{$zan_new_json}\,$content); $fp = @fopen($config_path,'w+'); @fwrite($fp,$content); //修改对应的数据表中的数据----5 $db->thisquery(update `.$db_prefix.ask_answers` set `goods`=`goods`+1 where `ans_id`=.$user_answer['answer_id'].); exit(); break; case 'cai'://踩(不给力) $cai_array = json_decode(str_replace(','',$cai_json),true); $user_answer['uid']=$uid; $user_answer['answer_id']=$_post['answer_id']; $cai_array[]=$user_answer; $config_path = 'shuzu/ovovsys_zan.php'; if(!file_exists($config_path)){ $base->errormsg('文件错误:shuzu/ovovsys_zan.php 不存在!');exit(); } $cai_new_json = str_replace('',',json_encode($cai_array)); $fp = @fopen($config_path,'r+'); if(!$content = @fread($fp,filesize($config_path))){ $base->errormsg('无法读取shuzu/ovovsys_zan.php文件!');exit(); } $content = str_replace(\$cai_json = \{$cai_json}\,\$cai_json = \{$cai_new_json}\,$content); $fp = @fopen($config_path,'w+'); @fwrite($fp,$content); $db->thisquery(update `.$db_prefix.ask_answers` set `bads`=`bads`-1 where `ans_id`=.$user_answer['answer_id'].); exit(); break;}?>
对应的数据文件(因为创建数据库时没有创建踩和赞的再断,所以这里就用php文件存变量的方式保存了一下答案对应的赞和踩的数据,其中包含用户的id和答案的id)
你没看错,就是两个变量
如果嫌复制着麻烦的话,也可以点击下载压缩文件,亲,不要积分的哟!
其它类似信息

推荐信息