简体   繁体   English

如何将日期与申请中的日期进行匹配?

[英]How do i match up dates with the days in my application?

This may seem a little basic but here is my issue. 这似乎有点基本,但这是我的问题。

function output_calendar($month, $year) {

    /* draw table */
    $calendar = '<table class="table table-bordered" cellpadding="0" cellspacing="0" class="calendar">';

    /* table headings */
    $headings = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
    $calendar.= '<tr><td>'.implode('</td><td>',$headings).'</td></tr>';

    /* days and weeks vars now ... */
    $running_day = date('w',mktime(0,0,0,$month,1,$year));
    $days_in_month = date('t',mktime(0,0,0,$month,1,$year));
    $days_in_this_week = 1;
    $day_counter = 0;
    $dates_array = array();

    /* row for week one */
    $calendar.= '<tr>';

    /* print "blank" days until the first of the current week */
    for($x = 0; $x < $running_day; $x++):
        $calendar.= '<td> </td>';
        $days_in_this_week++;
    endfor;

    /* keep going with days.... */
    for($list_day = 1; $list_day <= $days_in_month; $list_day++):
        $calendar.= '<td style="width:14%;height:10%;">';
            /* add in the day number */
            $calendar.= '<div>'.$list_day.'</div>';

            /** QUERY THE DATABASE FOR AN ENTRY FOR THIS DAY !!  IF MATCHES FOUND, PRINT THEM !! **/
            $calendar.= str_repeat('<p> </p>',2);

        $calendar.= '</td>';
        if($running_day == 6):
            $calendar.= '</tr>';
            if(($day_counter+1) != $days_in_month):
                $calendar.= '<tr>';
            endif;
            $running_day = -1;
            $days_in_this_week = 0;
        endif;
        $days_in_this_week++; $running_day++; $day_counter++;
    endfor;

    /* finish the rest of the days in the week */
    if($days_in_this_week < 8):
        for($x = 1; $x <= (8 - $days_in_this_week); $x++):
            $calendar.= '<td> </td>';
        endfor;
    endif;

    /* final row */
    $calendar.= '</tr>';

    /* end the table */
    $calendar.= '</table>';

    /* all done, return result */
    return $calendar; 
}

Front End JS 前端JS

                    $(document).ready(function () {
                        $(document).on('click', '#next', function() {
                            $("#main").empty();
                            if(display_month < 12) {
                            display_month++;
                            } else {
                            display_month = 1;
                            display_year++;
                            }
                            getCal(display_month, display_year);
                            $('#title').empty();
                            $('#title').html(months[display_month].concat(' ').concat(display_year));
                        });  
                        $(document).on('click', '#last', function() {
                            $("#main").empty();
                            if(display_month > 1) {
                            display_month--;
                            } else {
                            display_month = 12;
                            display_year--;
                            }
                            getCal(display_month, display_year);
                            $('#title').empty();
                            $('#title').html(months[display_month].concat(' ').concat(display_year));
                        }); 

                    });

                    // handles the click event, sends the query
                    function getCal(v1, v2) {
                    $.ajax({
                        url: "calGrab.php",
                       type: 'POST',
                       dataType: 'html',
                       data: content,
                        data: { 
                            "month": display_month, 
                            "year": display_year, 
                        },
                    }).done(function ( data ) {
                      $('#main').empty();
                      $('#main').append(data);
                    });
                    }

How do I go about correctly lining up the date with the associated day. 如何正确地将日期与相关的日期对齐。 For example, August starts on a Saturday for 2015. Are there any known techniques for this? 例如,八月在2015年的星期六开始。是否有已知的技术?

Please see prototype: http://calendar.conneraiken.com 请参阅原型: http : //calendar.conneraiken.com

You'd need 3 separate loops: 您需要3个单独的循环:

a) loop to pad calendar table with final days of previous month a)循环以上个月的最后几天填充日历表
b) loop to output current month b)循环输出当前月份
c) loop to pad calendar table with first days of next month c)循环以在下个月的第一天填充日历表

eg 例如

 Su M  T   W  Th  F Sa
 28 29 30  1  2   3  4   // 1st week of current month
 a  a  a   b  b   b  b   // loops used
      ....               // full weeks in current month, all loop 'b'
    28 29 30  1   2  3   // final week of current month
    b  b   b  c   c  c   //  loops used
$first = mktime(0,0,0,$month,1,$year);
$dow = date('w', $first);

# pad calendar for "end of last month"
echo '<tr>';
for($i = 0; $i < $dow; $i++) {
   echo '<td></td>';
}
... loop to output actual days in current month
... loop to pad final week with "next month" days to complete the row

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取JavaScript中两个日期之间的差值天? - How do I get the difference days between two Dates in JavaScript? 如何在javascript中显示接下来4天的日期? - How do I show the dates for the next 4 days in javascript? 如何在我的反应应用程序中设置 redux 商店? - How do I set up a redux store in my react application? 如何在 Vue Datepicker 中禁用当前日期前 14 天的所有日期? - How can I disable all dates up to 14 days ahead of the current date in Vue Datepicker? 如果我在JavaScript或jquery中有开始日期,如何显示一周中所有日期的日期? - How Do I display dates of all days of week if I have a start date in JavaScript or jquery? 如何通过引导程序日期范围选择器获取所选日期的天数? - How do I get days count for selected dates by bootstrap date range picker? 如何显示从Zebra Datepicker中选择的两个日期中选择的天数? - How do I display the number of days selected from two dates selected from Zebra Datepicker? 如何使用JavaScript返回两个日期之间的假日天数(假日除外)? - How do i use javascript to return the number of days holidays between two dates excluding holidays? 如何防止javascript将我的日期转换为GMT? - How do I prevent javascript from converting my dates to GMT? 如何停止javascript更改日期? - How do I stop javascript from altering my dates?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM