投票 赞踩
适合评论页面或者其他类似的地方,给鸡蛋或者鲜花等
数据库
SQL Code
- CREATE TABLE `voting_count` (
- `id` int(11) NOT NULL auto_increment,
- `unique_content_id` varchar(100) collate utf8_unicode_ci NOT NULL,
- `vote_up` int(11) NOT NULL,
- `vote_down` int(11) NOT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
XML/HTML Code
- <div class="content_wrapper">
- <h3>1
- <!-- voting markup -->
- <div class="voting_wrapper" id="1001">
- <div class="voting_btn">
- <div class="up_button"> </div><span class="up_votes">0</span>
- </div>
- <div class="voting_btn">
- <div class="down_button"> </div><span class="down_votes">0</span>
- </div>
- </div>
- <!-- voting markup end -->
- </h3>
- 各种下拉菜单,导航,多级菜单,右侧展开,左侧展开
- <h3>2
- <!-- voting markup -->
- <div class="voting_wrapper" id="1002">
- <div class="voting_btn">
- <div class="up_button"> </div><span class="up_votes">0</span>
- </div>
- <div class="voting_btn">
- <div class="down_button"> </div><span class="down_votes">0</span>
- </div>
- </div>
- <!-- voting markup end -->
- </h3>
- 翻页,分页,无刷新翻页,jquery翻页 本站演示中的分页数据库结构都一样的
- <h3>3
- <!-- voting markup -->
- <div class="voting_wrapper" id="1003">
- <div class="voting_btn">
- <div class="up_button"> </div><span class="up_votes">0</span>
- </div>
- <div class="voting_btn">
- <div class="down_button"> </div><span class="down_votes">0</span>
- </div>
- </div>
- <!-- voting markup end -->
- </h3>
- tab标签,选项卡,选卡,jquery选项卡,标签页,动态加载tab
- </div>
JavaScript Code
- <script type="text/javascript">
- $(document).ready(function() {
- //####### on page load, retrive votes for each content
- $.each( $('.voting_wrapper'), function(){
- //retrive unique id from this voting_wrapper element
- var unique_id = $(this).attr("id");
- //prepare post content
- post_data = {'unique_id':unique_id, 'vote':'fetch'};
- //send our data to "vote_process.php" using jQuery $.post()
- $.post('vote_process.php', post_data, function(response) {
- //retrive votes from server, replace each vote count text
- $('#'+unique_id+' .up_votes').text(response.vote_up);
- $('#'+unique_id+' .down_votes').text(response.vote_down);
- },'json');
- });
- //####### on button click, get user vote and send it to vote_process.php using jQuery $.post().
- $(".voting_wrapper .voting_btn").click(function (e) {
- //get class name (down_button / up_button) of clicked element
- var clicked_button = $(this).children().attr('class');
- //get unique ID from voted parent element
- var unique_id = $(this).parent().attr("id");
- if(clicked_button==='down_button') //user disliked the content
- {
- //prepare post content
- post_data = {'unique_id':unique_id, 'vote':'down'};
- //send our data to "vote_process.php" using jQuery $.post()
- $.post('vote_process.php', post_data, function(data) {
- //replace vote down count text with new values
- $('#'+unique_id+' .down_votes').text(data);
- //thank user for the dislike
- alert("Thanks! Each Vote Counts, Even Dislikes!");
- }).fail(function(err) {
- //alert user about the HTTP server error
- alert(err.statusText);
- });
- }
- else if(clicked_button==='up_button') //user liked the content
- {
- //prepare post content
- post_data = {'unique_id':unique_id, 'vote':'up'};
- //send our data to "vote_process.php" using jQuery $.post()
- $.post('vote_process.php', post_data, function(data) {
- //replace vote up count text with new values
- $('#'+unique_id+' .up_votes').text(data);
- //thank user for liking the content
- alert("Thanks! For Liking This Content.");
- }).fail(function(err) {
- //alert user about the HTTP server error
- alert(err.statusText);
- });
- }
- });
- //end
- });
- </script>
vote_process.php
PHP Code
- <?php
- require "../../conn.php";
- if($_POST)
- {
- ### connect to mySql
- //$sql_con = mysql_connect($db_host, $db_username, $db_password,$db_name)or die('could not connect to database');
- //get type of vote from client
- $user_vote_type = trim($_POST["vote"]);
- //get unique content ID and sanitize it (cos we never know).
- $unique_content_id = filter_var(trim($_POST["unique_id"]),FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH);
- //Convert content ID to MD5 hash (optional)
- $unique_content_id = $unique_content_id;
- //check if its an ajax request, exit if not
- if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
- die();
- }
- switch ($user_vote_type)
- {
- ##### User liked the content #########
- case 'up':
- //check if user has already voted, determined by unique content cookie
- if (isset($_COOKIE["voted_".$unique_content_id]))
- {
- header('HTTP/1.1 500 Already Voted'); //cookie found, user has already voted
- exit(); //exit script
- }
- //get vote_up value from db using unique_content_id
- $result = mysql_query("SELECT vote_up FROM voting_count WHERE unique_content_id='$unique_content_id' LIMIT 1");
- $get_total_rows = mysql_fetch_assoc($result);
- if($get_total_rows)
- {
- //found record, update vote_up the value
- mysql_query("UPDATE voting_count SET vote_up=vote_up+1 WHERE unique_content_id='$unique_content_id'");
- }else{
- //no record found, insert new record in db
- mysql_query("INSERT INTO voting_count (unique_content_id, vote_up) value('$unique_content_id',1)");
- }
- setcookie("voted_".$unique_content_id, 1, time()+7200); // set cookie that expires in 2 hour "time()+7200".
- echo ($get_total_rows["vote_up"]+1); //display total liked votes
- break;
- ##### User disliked the content #########
- case 'down':
- //check if user has already voted, determined by unique content cookie
- if (isset($_COOKIE["voted_".$unique_content_id]))
- {
- header('HTTP/1.1 500 Already Voted this Content!'); //cookie found, user has already voted
- exit(); //exit script
- }
- //get vote_up value from db using unique_content_id
- $result = mysql_query("SELECT vote_down FROM voting_count WHERE unique_content_id='$unique_content_id' LIMIT 1");
- $get_total_rows = mysql_fetch_assoc($result);
- if($get_total_rows)
- {
- //found record, update vote_down the value
- mysql_query("UPDATE voting_count SET vote_down=vote_down+1 WHERE unique_content_id='$unique_content_id'");
- }else{
- //no record found, insert new record in db
- mysql_query("INSERT INTO voting_count (unique_content_id, vote_down) value('$unique_content_id',1)");
- }
- setcookie("voted_".$unique_content_id, 1, time()+7200); // set cookie that expires in 2 hour "time()+7200".
- echo ($get_total_rows["vote_down"]+1);//display total disliked votes
- break;
- ##### respond votes for each content #########
- case 'fetch':
- //get vote_up and vote_down value from db using unique_content_id
- $result = mysql_query("SELECT vote_up,vote_down FROM voting_count WHERE unique_content_id='$unique_content_id' LIMIT 1");
- $row = mysql_fetch_assoc($result);
- //making sure value is not empty.
- $vote_up = ($row["vote_up"])?$row["vote_up"]:0;
- $vote_down = ($row["vote_down"])?$row["vote_down"]:0;
- //build array for php json
- $send_response = array('vote_up'=>$vote_up, 'vote_down'=>$vote_down);
- echo json_encode($send_response); //display json encoded values
- break;
- }
- }
- ?>
相关推荐
WordPress插件:Digg顶踩投票插件
2.会员的添加投票,投票管理,查看投票结果; 3.游客身份参加投票; 4.管理员添加投票信息、发布公告功能; 5.管理员对会员投票信息的审核功能; 6.管理员对投票的分类项目的管理和添加、修改功能; 系统
投票系统投票系统投票系统投票系统投票系统投票系统投票系统投票系统投票系统投票系统
投票投票投票投票投票投票投票投票投票投票投票
投票系统投票系统投票系统投票系统投票系统
基于Android的投票系统,...服务端部分以Web方式展现,为投票系统的后台管理部分,主要功能包括人员维护(投票人员、可发布投票人员、投票候选人或被评价人员等)、投票管理功能(发布投票、投票结果统计、导出等)。
微信公众平台投票系统功能: 全程界面后台自定义程度同类型最高,完全没有任何限制 微信投票源码提供多套投票主题风格可供选择 防刷票功能,后台开启验证码,可微信对话框输入id投票。 微信投票管理系统源码可以...
一款简单易用的开源投票系统,采用ASP+ACCESS开发,系统安装简单,将程序文件上传网站目录即可使用;功能完善,支持图文投票评选、支持自定义栏目,可以设置每个IP的的投票数以及每个IP对同一个选项的重复投票数等等...
python开发基于Django的投票系统源代码python开发基于Django的投票系统源代码python开发基于Django的投票系统源代码python开发基于Django的投票系统源代码python开发基于Django的投票系统源代码python开发基于Django...
微信小程序投票系统微信小程序云开发实现的投票微信小程序系统。瀑布流展示,排名,活动发布等功能微信小程序投票系统微信小程序云开发实现的投票微信小程序系统。瀑布流展示,排名,活动发布等功能微信小程序投票...
投票系统投票系统投票系统投票系统投票系统投票系统投票系统
在线投票系统是一种允许用户创建投票、参与投票和查看投票结果的应用程序。在这个实战博客中,我们将创建一个简单的Java在线投票系统,演示如何构建一个基本的投票应用。我们将使用Java编程语言和一些常见的开发库来...
518tt投票软件和其他自动投票软件的优势是:完全免费,设置简单,无需繁琐的参数,只需截取一段投票信息即可自动投票。 518tt投票软件功能: 智能高效:全自动投票,投票软件能自动拨号换ip 极速体验:投票速度快,...
一、跨平台支持微信、手机、平板投票,PC 无论使用智能手机、平板访问投票,都能展现良好的效果。更能与微信整合,实现微信投票。 跨平台的兼容性 使用智能手机、平板,均能访问投票生成的投票网址,并自动显示...
投票能手 功能特点: 1、简易投票模式为自学习型,只需按正常投票步骤操作一次,即可自动重复投票。 2、能实现用同一IP或自动转换IP投票。 3、高级模式中,开放所有设置,自定义表单,通过设置,能适用于...
上javaweb课时做的基于B/S模式的投票系统,附带写好的课程设计报告,建好数据库连上就能用(数据库表的设计在设计报告中)。 开发环境:JDK1.8、eclipse、SQL server 2008 R2、TomCat 7.0 系统的用户分为管理员用户...
主要实现业务: 用户投票,可附加一张图片,投票详情显示投票选项的比例及投票用户,非匿名投票可查看用户投票详情,投票结束时间到了,标记为投票结束(自动).用户可查看自己发起的投票和参与的投票,对于自己的...
投票系统能增加投票信息,删除投票信息,统计投票信息等。系统规定,针对每一个投票问题,每一个投票人仅能有一次投票机会,根据VIP与否(非VIP标记为not),计算票数的方法也不同(VIP投1票等于非VIP投3票)。涉及...
投票系统需求分析 投票系统需求分析 投票系统需求分析 投票系统需求分析 投票系统需求分析 投票系统需求分析 投票系统需求分析
微信投票系统投票系统