• php 日历代码


    日历的PHP接口代码:

    $user_id = $_SESSION['user_id'];
        $year = isset($_REQUEST['tty']) ? intval($_REQUEST['tty']) : date('Y');
        $month = isset($_REQUEST['ttm']) ? intval($_REQUEST['ttm']) : date('m');
        //获取当前月有多少天
        $days = date('t', strtotime("{$year}-{$month}-1"));
        // 当前1号是星期几
        $week = date('w', strtotime("{$year}-{$month}-1"));
        // 实现上一月和上一年
        if ($month == 1) {
            $premonth = 12;
            $preyear = $year - 1;
        } else {
            $premonth = $month - 1;
            $preyear = $year;
        }
        // 实现下一月和下一年
        if ($month == 12) {
            $nextmonth = 1;
            $nextyear = $year + 1;
        } else {
            $nextmonth = $month + 1;
            $nextyear = $year;
        }
        $dayss = array();
        for ($i = 1; $i <= $week; $i++) {
            $dayss[] = '';
        }
        for ($i = 1; $i <= $days; $i++) {
            $dayss[] = $i;
        }
        // 获取签到所有数据(本月中)
        $start = strtotime("{$year}-{$month}-1");
        $end = strtotime("{$nextyear}-{$nextmonth}-1") - 1;
        $logsql = 'SELECT * FROM ' . $ecs->table('hpyer_sign_log') . " where uid={$user_id} AND add_time between {$start} AND {$end}";
        $loglist = $db->getAll($logsql);
        $loginfo = array();
        foreach ($loglist as $v) {
            $loginfo[] = intval(date('d', $v['add_time']));
        }
    
    
        $result = array(
            'code' => 1,
            'data' => array(
                'year' => $year,
                'month' => $month,
                'preyear' => $preyear,
                'premonth' => $premonth,
                'nextyear' => $nextyear,
                'nextmonth' => $nextmonth,
                'days' => $dayss,
                'loginfo' => $loginfo
            )
        );
        die($jsonr->encode($result));

    HTML接口说明:

    $('.riQh').on('click', function() {
        var tty = $(this).attr('tty'),
            ttm = $(this).attr('ttm');
        $.ajax({
            url: '/mobile/ajaxnew.php',
            data: {
                act: 'rili',
                tty: tty,
                ttm: ttm
            },
            type: 'post',
            dataType: 'json',
            success: function(res) {
                console.log(res);
                if (res.code == 1) {
                    $('.riz').attr('tty', res.data.preyear);
                    $('.riz').attr('ttm', res.data.premonth);
                    $('.riy').attr('tty', res.data.nextyear);
                    $('.riy').attr('ttm', res.data.nextmonth);
                    $('#nowdate').text(res.data.year + '年' + res.data.month + '月');
                    var zoninfo = '';
                    for (var i = 0; i < res.data.days.length; i++) {
                        if(res.data.loginfo.indexOf(res.data.days[i]) >-1){
                            zoninfo += '<li class="active">'+res.data.days[i]+'</li>';
                        }else{
                            zoninfo += '<li>'+res.data.days[i]+'</li>';
                        }
                    }
                    $('#rilihtml').html(zoninfo);
                } else {
                    alert('获取数据失败!');
                }
            }
        });
    });
  • 相关阅读:
    Maven学习总结(八)——使用Maven构建多模块项目
    Maven学习总结(七)——eclipse中使用Maven创建Web项目
    Maven学习总结(六)——Maven与Eclipse整合
    Maven学习总结(五)——聚合与继承
    BBS的登陆——发帖——回帖
    bugfree,CDbConnection 无法开启数据库连线: SQLSTATE[HY000] [2003] Can't connect to MySQL server on '192.168.0.99' (4)
    Mac 中配置Apache
    Mac里安装配置Jdk
    启动mongodb遇到的错:warning: 32-bit servers don't have journaling enabled by deflity
    分享组2015.7.31
  • 原文地址:https://www.cnblogs.com/ziyandeyanhuo/p/10217952.html
Copyright © 2020-2023  润新知