• 技术文章 >php教程 >PHP源码

    jquery php ajax 投票程序源码

    2016-06-08 17:25:55原创692
    一款免费的jquery php ajax 投票程序源码,你可以在本教程最后找到这款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");

    ?>






    jquery php ajax 投票程序源码





    // 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 '

      ';

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

      while($row=mysql_fetch_assoc($res))
      {?>




    • <?php echo $row['title']?>

















    }
    else require "results.php";
    // the above require saves us from having to style another separate page

    ?>






    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.='

    ';
    }

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

    ?>


    go back

    votes

    源码下载


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

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:nbsp quot gt lt mysql
    上一篇:简单php文件上传实例 下一篇:php 缓存技术(1/4)
    VIP课程(WEB全栈开发)

    相关文章推荐

    • 【腾讯云】年中优惠,「专享618元」优惠券!• 收藏PHP常用自定义函数• php微信支付接口开发程序(流程已通)• Php自用分页函数程序代码• php对多维数组的某个键值排序方法• 检测移动设备的php代码(手机访问)
    1/1

    PHP中文网