jquery php ajax 投票程序源码

 代码如下 复制代码

/* database config */

$db_host  = '';
$db_user  = '';
$db_pass  = '';
$db_database  = '';

/* end config */

 

$link = mysql教程_connect($db_host,$db_user,$db_pass) or die('unable to establish a db connection');

mysql_select_db($db_database,$link);
mysql_query("set names utf8");

?>

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>jquery php ajax 投票程序源码</title>

<link rel="stylesheet" type="text/css教程" href="demo.css" />

<script type="text/网页特效" src="">http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">>
<script type="text/javascript" src="">http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js">>

<script type="text/javascript" src="script.js"></script>

</head>

<body>

<div id="main">
 

 <hr />

 
<?php

// checking whether the user has voted today:

$voted=false;

$vcheck=mysql_query(" select 1 from sort_votes
      where ip='".$_server['remote_addr']."'
      and date_submit=curdate()");

if(mysql_num_rows($vcheck)==1)
 $voted=true;

// if we are not on the data.php?results page:
if(!array_key_exists('results',$_get))
{
 echo '<ul class="sort">';

 // showing the tutorials by random
 $res = mysql_query("select * from sort_objects order by rand()");

 while($row=mysql_fetch_assoc($res))
 {?>
     <li id="li<?php echo $row['id']?>">
  <div class="tut">
            <div class="tut-img">
                <img src="<?php echo $row['img']?>" width="100" height="100" alt="<?php echo $row['title']?>" />
                <div class="drag-label"></div>
            </div>
           
            <div class="tut-title">
             <a href="<?php echo $row['url']?>" target="_blank" title="open it in a new window!"><?php echo $row['title']?></a>
            </div>
           
            <div class="tut-description"><?php echo $row['description']?></div>
            <div class="clear"></div>
        </div>
        </li>
 <?php } ?>
   
   </ul>
 
 <div class="button-holder">
     <?php if(!$voted):?><a href="" id="submitpoll" class="button">submit poll<span></span></a><?php endif;?>
        <a href="?results" class="button">view the results<span></span></a>
    </div>
 
<?php
}
else require "results.php";
// the above require saves us from having to style another separate page

?>
   
 <div class="clear"></div>   
   

<!-- the form below is not directly available to the user -->

<form action="?results" id="sform" method="post">
<input name="sortdata" id="sortdata" type="hidden" value="" />
</form>

</body>
</html>

results.php

if($_post['sortdata'])
{
 // the data arrives as a comma-separated string,
 // so we extract each post ids:
 $data=explode(',',str_replace('li','',$_post['sortdata']));

 // getting the number of objects
 list($tot_objects) = mysql_fetch_array(mysql_query("select count(*) from sort_objects"));

 if(count($data)!=$tot_objects) die("wrong data!");

 foreach($data as $k=>$v)
 {
  // building the sql query:
  $str[]='('.(int)$v.','.($tot_objects-$k).')';
 }
 
 $str = 'values'.join(',',$str);
 
 // this will limit voting to once a day per ip:
 mysql_query(" insert into `sort_votes` (ip,date_submit,dt_submit)
     values ('".$_server['remote_addr']."',now(),now())");

 // if the user has not voted before today:
 if(mysql_affected_rows($link)==1)
 {
  mysql_query(' insert into `sort_objects` (id,votes) '.$str.'
      on duplicate key update votes = votes+values(votes)');
 }
}

// selecting the sample tutorials and ordering
// them by the votes each of them received:
$res = mysql_query("select * from sort_objects order by votes desc");

$maxvote=0;
$bars=array();

while($row=mysql_fetch_assoc($res))
{
 $bars[]=$row;
 
 // storing the max vote, so we can scale the bars of the chart:
 if($row['votes']>$maxvote) $maxvote = $row['votes'];
}

$barstr='';

// the colors of the bars:
$colors=array('#ff9900','#66cc00','#3399cc','#dd0000','#800080');

foreach($bars as $k=>$v)
{
 // buildling the bar string:
 $barstr.='
  <div class="bar" style="width:'.max((int)(($v['votes']/$maxvote)*450),100).'px;background:'.$colors[$k].'">
   <a href="'.$v['url'].'" title="'.$v['title'].'">'.$v['short'].'</a> 
  </div>';
}

// the total number of votes cast in the poll:
list($totvotes) = mysql_fetch_array(mysql_query("select count(*) from sort_votes"));

?>

<div class="chart">

<?php echo $barstr?>

</div>

<a href="demo.php" class="button">go back<span></span></a>

<div class="tot-votes"><?php echo $totvotes?> votes</div>

源码下载

http://down.111cn.net/down/code/php/toupiaodiaocha/2010/1028/21481.html

时间: 2024-07-31 12:11:50

jquery php ajax 投票程序源码的相关文章

一个简单的PHP投票程序源码_php实例

分析:  我们利用一个文件(data.dat)来存储投票栏目.每个栏目占据一行.  这样一来,便可随意加入和减去想要投票的栏目.  我们再利用一个文件(votes.dat)来存储我们的投票结果.  并纪录最近一位投票者的IP地址,简单的防止一人多投.  所以,您应该在该程序目录下自行建立两个文件data.dat和votes.dat  程序运行过程部分  程序运行时应该先有一个投票的HTML表单,等待投票.  当有人在HTML表单上投票时,判断它的IP是否为最近一位投票者的IP,  如果此人刚刚投

基于jquery图片左右滚动效果源码

基于jquery图片左右滚动效果源码 这是一款来自网络的图片可控的左右滚动效果源码,有需要的朋友可以参考一下. <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>slide</title> <script type="text/网页特效" src="http://ajax.googleapis.com/ajax

php ajax拖动购物车源码

以前我们的购物车都是点击打开网页,都是web 2.0形式的,本文章提供这款php教程 ajax拖动购物车源码,可以拖动商品放在购物车里面,这样更好的适合用户习惯了. */ //download by http://www.111cn.net /* database config */ $db_host  = 'localhost'; $db_user  = 'root'; $db_pass  = 'dcfan2006'; $db_database = 'test'; $link = mysql教

初学者的忧伤-用autocomplete插件结合ajax后台访问源码报错

问题描述 用autocomplete插件结合ajax后台访问源码报错 用autocomplete插件结合ajax后台访问源码报错:Uncaught TypeError: Cannot read property 'length' of undefined.这是什么原因,谁知道啊. 链接为http://www.runoob.com/jqueryui/example-autocomplete.html.在里面的远程 JSONP 数据源demo,没有正确的数据. 解决方案 自己看api,http://

c语言-求蜘蛛纸牌c程序源码!!!

问题描述 求蜘蛛纸牌c程序源码!!! 求电脑游戏蜘蛛纸牌c程序源码,急急急! 各位大神,帮帮忙!!! 解决方案 http://www.codeforge.cn/read/120284/SpiderView.cpp__html 解决方案二: 带不带界面呢.可视化?

c#网络编程-求c# socket聊天程序源码

问题描述 求c# socket聊天程序源码 我用c# winform自己写了一个局域网通信的软件,但是有点问题.求源码,类似QQ那样的,但我只要能实现在局域网聊天就行!! 解决方案 http://www.newxing.com/Code/CSharp/SOCKET_62.html 解决方案二: http://blog.csdn.net/liuwenqiangcs/article/details/7485950http://www.cnblogs.com/guoyiqi/archive/2011/

商品网站信息-求一个可用的爬虫程序源码

问题描述 求一个可用的爬虫程序源码 爬取商品网站信息 http://www.soukai.com 有的发我邮箱,感激不尽 728735816@qq.com 解决方案 写完了,挺简单的,写了一个下午 解决方案二: 最好是java 或者python的

android recovery升级时执行的程序源码在哪里??

问题描述 android recovery升级时执行的程序源码在哪里?? 我再详细说明一下:当从应用层跳转到recovery后,如果执行升级,执行的程序对应的源码位置在哪里(个人感觉好像不是bootable/recovery下面的recovery.cpp) 解决方案 recovery.cpp算是整个recovery的入口吧,你还得看看 bootable/recovery/updater下的install.c, 这个会生成脚本程序(印象中是python脚本), 脚本程序又是根据升级包update.

求一个基于ajax的电子地图源码

问题描述 毕业论文是基于ajax的电子地图,但本人对java熟一点.所以希望有人提供一个基于ajax的电子地图源码,或者指点写开始思路.因为以前都是做web的对这方面不熟!谢谢! 解决方案 解决方案二:google地图API