<bdo id='j4Kgk'></bdo><ul id='j4Kgk'></ul>
<legend id='j4Kgk'><style id='j4Kgk'><dir id='j4Kgk'><q id='j4Kgk'></q></dir></style></legend>

<i id='j4Kgk'><tr id='j4Kgk'><dt id='j4Kgk'><q id='j4Kgk'><span id='j4Kgk'><b id='j4Kgk'><form id='j4Kgk'><ins id='j4Kgk'></ins><ul id='j4Kgk'></ul><sub id='j4Kgk'></sub></form><legend id='j4Kgk'></legend><bdo id='j4Kgk'><pre id='j4Kgk'><center id='j4Kgk'></center></pre></bdo></b><th id='j4Kgk'></th></span></q></dt></tr></i><div id='j4Kgk'><tfoot id='j4Kgk'></tfoot><dl id='j4Kgk'><fieldset id='j4Kgk'></fieldset></dl></div>

<small id='j4Kgk'></small><noframes id='j4Kgk'>

    1. <tfoot id='j4Kgk'></tfoot>

      PHP+ajax+mysql+layui实现每日签到及提醒功能

      时间:2023-10-17
    2. <legend id='NuyMR'><style id='NuyMR'><dir id='NuyMR'><q id='NuyMR'></q></dir></style></legend>
      • <bdo id='NuyMR'></bdo><ul id='NuyMR'></ul>
      • <tfoot id='NuyMR'></tfoot>
          <tbody id='NuyMR'></tbody>

          <small id='NuyMR'></small><noframes id='NuyMR'>

              <i id='NuyMR'><tr id='NuyMR'><dt id='NuyMR'><q id='NuyMR'><span id='NuyMR'><b id='NuyMR'><form id='NuyMR'><ins id='NuyMR'></ins><ul id='NuyMR'></ul><sub id='NuyMR'></sub></form><legend id='NuyMR'></legend><bdo id='NuyMR'><pre id='NuyMR'><center id='NuyMR'></center></pre></bdo></b><th id='NuyMR'></th></span></q></dt></tr></i><div id='NuyMR'><tfoot id='NuyMR'></tfoot><dl id='NuyMR'><fieldset id='NuyMR'></fieldset></dl></div>

                这篇文章主要为大家详细介绍了使用PHP+layui实现每日签到及提醒功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,首次签到获得1个积分,第二次签到获得2个积分,第三次签到获得3个积分,以此类推但是签到必须每天连续积分才可以递增,如果有中断再次签到时获得积分仍然从1开始递增,实现效果如下:


                数据库设计:

                -- --------------------------------------------------------
                -- 主机:                           127.0.0.1
                -- 服务器版本:                        5.5.53 - MySQL Community Server (GPL)
                -- 服务器操作系统:                      Win32
                -- HeidiSQL 版本:                  9.3.0.4984
                -- --------------------------------------------------------
                /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
                /*!40101 SET NAMES utf8mb4 */;
                /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
                /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
                -- 导出 sg 的数据库结构
                CREATE DATABASE IF NOT EXISTS `sg` /*!40100 DEFAULT CHARACTER SET utf8 */;
                USE `sg`;
                -- 导出  表 sg.user 结构
                CREATE TABLE IF NOT EXISTS `user` (
                 `id` int(11) NOT NULL AUTO_INCREMENT,
                 `username` varchar(50) NOT NULL,
                 `count` int(11) NOT NULL,
                 `point` int(11) NOT NULL,
                 `sign_time` datetime NOT NULL,
                  PRIMARY KEY (`id`)
                ) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
                -- 正在导出表  sg.user 的数据:0 rows
                /*!40000 ALTER TABLE `user` DISABLE KEYS */;
                INSERT IGNORE INTO `user` (`id`, `username`, `count`, `point`, `sign_time`) VALUES
                    (1, '1', 3, 3, '2018-12-03 15:19:26'),
                    (2, '2', 2, 2, '2018-12-03 15:03:38'),
                    (3, '3', 1, 1, '2018-12-03 15:56:38');
                /*!40000 ALTER TABLE `user` ENABLE KEYS */;
                /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
                /*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */;
                /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

                引入jquery和layui,PS:注意需要先下载layui并使用layui.all.js

                <script src="https://cdn.bootcss.com/jquery/1.12.0/jquery.min.js"></script>
                <script src="./layui/layui.all.js" charset="utf-8"></script>
                <link rel="stylesheet" href="./layui/css/layui.css" media="all">

                index.html前端,页面布局<怎么好看看自己需要了,我只是简单的写了一个>

                <center>
                <input type="text" name="username">
                <button>签到</button>
                </br>
                <span id='span'></span>
                <div>
                 <table id="box" border="1"></table>
                </div>
                </center>
                AJAX提交:
                $(function(){
                    $('button').click(function(){
                      var username=$(':text').val();
                      $.ajax({
                        type:'post',
                        url:'admin.php',
                        data:{username:username},
                        dataType:'json',
                        success:function(res){
                          if(res.success==1){
                            layer.alert(res.info, {
                            icon: 1,
                            title: "提示"
                            });
                            var str='<tr><td>用户名</td><td>连续签到天数</td><td>总积分</td></tr>';
                            str+='<tr><td>'+res.msg.username+'</td><td>'+res.msg.count+'</td><td>'+res.msg.point+'</td></tr>';
                            $('#box').html(str);
                          }
                        }
                      })
                    });
                  })
                PHP处理文件:
                <?php
                error_reporting(0);
                header("content-type:text/html;charset=utf-8");
                date_default_timezone_set('PRC');
                $dsn = 'mysql:host=localhost;dbname=sg';
                $pdo = new PDO($dsn, 'root', '123456');
                $pdo->exec('set names utf8');
                $username = $_POST['username'];
                $sqlQuery = "select * from user where username='$username'";
                $row = $pdo->query($sqlQuery)->fetch(PDO::FETCH_ASSOC);
                if ($row) {
                    $sign_time = $row['sign_time'];
                    $sign_time = strtotime($sign_time);
                    //echo $sign_time;
                    $int = date('Y-m-d');
                    //echo $int;
                    $int = strtotime($int);
                    $ints = $int + 86400;    
                    $int_s = $int - 86400;    
                        //当天已签到
                    if ($int < $sign_time && $sign_time < $ints) {
                        $infor ="今天您已经签过到了,请明天再来!";//echo '您已签到';
                    }
                    //昨天未签到,积分,天数在签到修改为1
                    if ($sign_time < $int_s) {
                        $count = 1;
                        $point = 1;
                        $sign_time = date('Y-m-d H:s:i');
                        $sqlRow = "update user set count='$count',point='$point',sign_time='$sign_time' where username='$username'";
                        $res = $pdo->exec($sqlRow);
                        // echo '签到成功修改为1';
                    }
                    //请签到
                    if ($int_s < $sign_time && $sign_time < $int) {
                        $count = $row['count'] + 1;
                        $point = $row['point'] + 1;
                        $sign_time = date('Y-m-d H:s:i');
                        $sqlupdate = "update user set count='$count',point='$point',sign_time='$sign_time' where username='$username'";
                        $res = $pdo->exec($sqlupdate);
                        $infor ="签到成功!";// echo '签到成功+1';
                    }
                } else {
                    $count = 1;
                    $point = 1;
                    $sign_time = date('Y-m-d H:s:i');
                    $sqlAdd = "insert into user values (null,'$username','$count','$point','$sign_time')";
                    $res = $pdo->exec($sqlAdd);
                    $infor ="签到成功!请记得再来哦!";// echo '恭喜你签到成功----1';
                }
                //////////////////////响应
                $sqlEnd = "select * from user where username='$username'";
                $info = $pdo->query($sqlEnd)->fetch(PDO::FETCH_ASSOC);
                echo json_encode(array('success' => 1, 'info'=>$infor,'msg' => $info));
                die;
                ?>
                 
                上一篇:php随机获取数组的值 下一篇:没有了

                相关文章

                  <legend id='9WBNB'><style id='9WBNB'><dir id='9WBNB'><q id='9WBNB'></q></dir></style></legend>

                    <tfoot id='9WBNB'></tfoot>

                    • <bdo id='9WBNB'></bdo><ul id='9WBNB'></ul>
                    <i id='9WBNB'><tr id='9WBNB'><dt id='9WBNB'><q id='9WBNB'><span id='9WBNB'><b id='9WBNB'><form id='9WBNB'><ins id='9WBNB'></ins><ul id='9WBNB'></ul><sub id='9WBNB'></sub></form><legend id='9WBNB'></legend><bdo id='9WBNB'><pre id='9WBNB'><center id='9WBNB'></center></pre></bdo></b><th id='9WBNB'></th></span></q></dt></tr></i><div id='9WBNB'><tfoot id='9WBNB'></tfoot><dl id='9WBNB'><fieldset id='9WBNB'></fieldset></dl></div>

                  1. <small id='9WBNB'></small><noframes id='9WBNB'>