Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何对日历脚本运行多个查询以使一天不可用_Php_Mysqli_Calendar - Fatal编程技术网

Php 如何对日历脚本运行多个查询以使一天不可用

Php 如何对日历脚本运行多个查询以使一天不可用,php,mysqli,calendar,Php,Mysqli,Calendar,我有一个日历脚本,在任何给定的一天,每天早上和下午最多显示6个约会。它计算剩余的数量,如果全部取下6个,则显示已满。我还想做的是能够将一个上午、下午、一整天甚至整个星期(例如,对于假日)划掉,并将它们标记为已满,而无需向db中添加6/12/84行 我尝试添加一个名为“block”的列,并在给定的一天内将其值设置为1,默认值为0,但无法同时运行两个查询。然后,它不会显示仍有6个约会的日期(即,数据库中没有任何行,因此块值不为0或1)。我尝试了各种嵌套2 while循环的方法,我尝试了sql中的IF

我有一个日历脚本,在任何给定的一天,每天早上和下午最多显示6个约会。它计算剩余的数量,如果全部取下6个,则显示已满。我还想做的是能够将一个上午、下午、一整天甚至整个星期(例如,对于假日)划掉,并将它们标记为已满,而无需向db中添加6/12/84行

我尝试添加一个名为“block”的列,并在给定的一天内将其值设置为1,默认值为0,但无法同时运行两个查询。然后,它不会显示仍有6个约会的日期(即,数据库中没有任何行,因此块值不为0或1)。我尝试了各种嵌套2 while循环的方法,我尝试了sql中的IF EXISTS,PHP中的EXISTS/isset,但就是无法让它工作。有人能帮忙吗

date_default_timezone_set('Europe/London');
// Get prev & next month
if (isset($_GET['ym'])) {
    $ym = $_GET['ym'];
} else {
    // This month
    $ym = date('Y-m');
}
// Check format
$timestamp = strtotime($ym . '-01');  // the first day of the month
if ($timestamp === false) {
    $ym = date('Y-m');
    $timestamp = strtotime($ym . '-01');
}
// Today (Format:2018-08-8)
$today = date('Y-m-d');
$todaynum = date('N');
$hour = date('a');
// Title (Format:August, 2018)
$title = date('F, Y', $timestamp);
// Display Month (Format: August), Display Year (Format: 2018)
$dismth = date(' F ', $timestamp);
$disyr = date('Y', $timestamp);
// Current Year (Format:2018-), Current Month (Format:08-),
$curryr = date('Y-', $timestamp);
$currmth = date('m-', $timestamp);
// Create prev & next month link
$prev = date('Y-m', strtotime('-1 month', $timestamp));
$next = date('Y-m', strtotime('+1 month', $timestamp));
// Number of days in the month
$day_count = date('t', $timestamp);
// 1:Mon 2:Tue 3: Wed ... 7:Sun
$str = date('N', $timestamp);
// Array for calendar
$weeks = [];
$week = '';

// Add empty cell(s)
$week .= str_repeat('<td></td>', $str - 1);
for ($day = 1; $day <= $day_count; $day++, $str++) {

/* create a variable to concantenate the dates into db format */
/*$chosen = $curryr.$currmth.$day;*/
if ($day < 10) {
    $date = $ym . '-0' . $day;
}
else {
    $date = $ym . '-' . $day;
}
/* find if it's a weekend */
$weekdays = strtotime($date);
$weekday = date('l', $weekdays);
/* create a variable to concantenate the day and dates into display format */
$display = $weekday.', '.$day.$dismth.$disyr;

/* query - count number of appointments for current day and time */
$sqlam = "SELECT count(*) AS amapp FROM wasps_appointments WHERE date = '$date' AND time = 'Morning'";
$resultam = $connection->query($sqlam);
$sqlpm = "SELECT count(*) AS pmapp FROM wasps_appointments WHERE date = '$date' AND time = 'Afternoon'";
$resultpm = $connection->query($sqlpm);



/* start cell - check if today and if yes add class */
if ($today == $date) {
    $week .= '<td class="today">';
} else {
    $week .= '<td>';
}
/* Write day number into cell */
$week .= '<span class="date">';
$week .= $day;
$week .= '</span>';

/* if weekend show nothing */
if ( $weekday == 'Saturday' || $weekday == 'Sunday' ){            }


/* else (if not weekend) show links */
else {

/* ------------------------ MORNING -----------------------*/

            /* display morning appointment availability from query above */
            while($row = mysqli_fetch_array($resultam)){
                /* if in the future show links */
                if ($date >= $today){
                    /* count how many remaining */
                    $amremain = 6 - $row['amapp'];
                    /* change colour according to availability*/
                                                                   $trafficlight = "green";
                    if      ($amremain == 3 || $amremain == 2)   { $trafficlight = "amber";}
                    elseif  ($amremain == 1)                     { $trafficlight = "red";}
                    /* check if fully booked */
                    if ($amremain == 0) {
                        $week .= 'am <span class="am full">FULL</span><br />';
                    }
                    else {
                        /* write dates into form fields from link */
                        $week .= 'am <span class="am '.$trafficlight.'"><a href="#form" onClick="document.getElementById(\'displaydate\').value=\'' . $display . '\';document.getElementById(\'chosendate\').value=\'' . $date . '\';document.getElementById(\'displaytime\').value=\'Morning\'">' . $amremain . '&nbsp;left</a></span><br />';
                    }
                }
                /* else if in the past show nothing */
                else { }
            }


/* ------------------------ END MORNING -----------------------*/


/* ------------------------ AFTERNOON -----------------------*/

            /* display afternoon appointment availability from query above */
            while($row = mysqli_fetch_array($resultpm)){
                /* if in the future show links */
                if ($date >= $today){
                    $pmremain = 6 - $row['pmapp'];
                    /* change colour according to availability*/
                                                                   $trafficlight = "green";
                    if      ($pmremain == 3 || $pmremain == 2)   { $trafficlight = "amber";}
                    elseif  ($pmremain == 1)                     { $trafficlight = "red";}
                    if ($pmremain == 0) {
                        $week .= 'pm <span class="pm full">FULL</span>';
                    }
                    else {
                        /* write dates into form fields from link */
                        $week .= 'pm <span class="pm '.$trafficlight.'"><a href="#form" onClick="document.getElementById(\'displaydate\').value=\'' . $display . '\';document.getElementById(\'chosendate\').value=\'' . $date . '\';document.getElementById(\'displaytime\').value=\'Afternoon\'">' . $pmremain . '&nbsp;left</a></span>';
                    }
                }
                /* else if in the past show nothing */
                else { }
            }

/* ------------------------ END AFTERNOON -----------------------*/

}
/* end cell */
$week .= '</td>';
// Sunday OR last day of the month
if ($str % 7 == 0 || $day == $day_count) {
    // last day of the month
    if ($day == $day_count && $str % 7 != 0) {
        // Add empty cell(s)
        $week .= str_repeat('<td></td>', 7 - $str % 7);
    }
    $weeks[] = '<tr>' . $week . '</tr>';
    $week = '';
}



}

?>

<div id="calendar">
    <div class="datenavigation"><a href="?ym=<?= $prev; ?>#calendar">&lt; prev</a> &nbsp; <span class="title"><?= $title; ?></span> &nbsp; <a href="?ym=<?= $next; ?>#calendar">next &gt;</a><!-- <a href="#calendar">today</a>--></div>
    <div class="key"><span class="am">Morning 8am to 12pm</span><br /><span class="pm">Afternoon 1pm to 6pm</span></div>

    <table>
        <thead>
            <tr>
                <th>M</th>
                <th>T</th>
                <th>W</th>
                <th>T</th>
                <th>F</th>
                <th>S</th>
                <th>S</th>
            </tr>
        </thead>
        <tbody>
            <?php
                foreach ($weeks as $week) {
                    echo $week;
                }
            ?>
        </tbody>
    </table>
</div>
date\u default\u timezone\u set(“欧洲/伦敦”);
//获取上一个月和下个月
如果(isset($_GET['ym'])){
$ym=$_GET['ym'];
}否则{
//这个月
$ym=日期('Y-m');
}
//检查格式
$timestamp=strottime($ym.'-01');//月初一
如果($timestamp==false){
$ym=日期('Y-m');
$timestamp=strottime($ym.-01');
}
//今天(格式:2018-08-8)
$today=日期('Y-m-d');
$todaynum=日期('N');
$hour=日期('a');
//标题(格式:2018年8月)
$title=日期('F,Y',$timestamp);
//展示月(格式:8月)、展示年(格式:2018年)
$dismth=日期('F',$timestamp);
$disyr=日期('Y',$timestamp);
//本年度(格式:2018-),本月(格式:08-),
$curryr=日期('Y-',$timestamp);
$currmth=日期('m-',$timestamp);
//创建上个月和下个月链接
$prev=日期('Y-m',标准时间('-1个月',$timestamp));
$next=日期('Y-m',标准时间('+1个月',$timestamp));
//当月天数
$day_count=日期('t',$timestamp);
//1:Mon 2:Tue 3:Wed。。。7:太阳
$str=日期('N',$timestamp);
//日历数组
$weeks=[];
$week='';
//添加空单元格
$week.=str_重复(“”,$str-1);
对于($day=1;$day)