简体   繁体   English

PHP日历显示几个

[英]PHP Calendar Display Several

I am doing a week-by-week (24 hour calendar), this is going to be used to record what hours have been booked and on what days. 我每周进行一次工作(24小时制),这将用于记录已预订的小时数和日期。

It's like a timetable with slots that you book. 这就像您预订的带有时间表的时间表。 To ensure that booked and unbooked slots were different I put in PHP if statements to check the time against the database. 为了确保已预订和未预订的插槽不同,我在PHP if语句中放入了针对数据库检查时间的语句。

Problem being; 问题存在; I believe my if statements are only working for one row unlike a while statement that works over several. 我相信我的if语句仅适用于一行,而while语句则适用于多个行。 - so basically I want to be able to book more than one hour per day - and see more than one hour per day -所以基本上我希望每天可以预订超过一小时-每天可以看到一小时以上

(the database insert isn't a problem - displaying it on the calendar is) (数据库插入不是问题-在日历上显示它是)

I cannot do a while statement as I am unsure how I would structure my schedule/calendar with one. 我不能做一会儿陈述,因为我不确定如何用一个表来安排我的时间表/日历。

Here is an my problem: http://postimage.org/image/gcb3x3fk3/ (if I booked 18:00 on Sep 9 - it wouldn't show) 这是我的问题: http : //postimage.org/image/gcb3x3fk3/ (如果我在9月9日预订18 : 00-它不会显示)

$globalid is a global variable and is not held within the file/code below (but is included) $ globalid是全局变量,不保存在下面的文件/代码中(但包含在内)

MY CODE 我的密码

<div id="calendar">
<?
if(isset($_POST['add_week'])){
    $week = date('d-m-Y', strtotime($_POST['last_week']));
    $new_week =  strtotime ( '+1 week' , strtotime ( $week ) ) ;
    $new_week = date('d-m-Y', $new_week);


    $week_number = date("W", strtotime( $new_week));
    $year = date("Y", strtotime( $new_week));
}else if(isset($_POST['back_week'])){
    $week = date('d-m-Y', strtotime($_POST['last_week']));
    $new_week =  strtotime ( '-1 week' , strtotime ( $week ) ) ;
    $new_week = date('d-m-Y', $new_week);


    $week_number = date("W", strtotime( $new_week));
    $year = date("Y", strtotime( $new_week));
}else{

$week_number = date("W");
$year = date("Y");
}
/*if($week_number < 10){
   $week_number = "0".$week_number;
}*/
$week_start = date('d-m-Y', strtotime($year."W".$week_number,0));
?>

<table name="week" width="100%" cellspacing="0" cellpadding="0" height="13">
    <tr>
<?
for($day=1; $day<=7; $day++)
{
?>
<tr>
<td class="day">
<?
$daycal = date('d M', strtotime($year."W".$week_number.$day))."";
echo $daycal;
?>
</td>
<td width="3"> </td>
<td>
<!-- Timetable -->
<table width="100%" cellspacing="0" cellpadding="0" height="13">
<tr><td>
<?
// Do not edit Below
$cal = mysql_query("SELECT * FROM `calendar` WHERE `day`='$daycal' && `userid`='$globalid'")or die(mysql_error());
$calendar = mysql_fetch_array($cal);
?>
<div class="hour" name="00:00" id="<? echo $daycal; ?>">
<?
if($calendar['time']=="00:00"){ 
?>
Booked
<? }else{ ?>
00:00
<? } ?>
</div>
<div class="hour" name="01:00" id="<? echo $daycal; ?>">
<?
if($calendar2['time']=="01:00"){ 
?>
Booked
<? }else{ ?>
01:00
<? } ?>
</div>
<div class="hour" name="02:00" id="<? echo $daycal; ?>">
<?
if($calendar3['time']=="02:00"){ 
?>
Booked
<? }else{ ?>
02:00
<? } ?>
</div>
<div class="hour" name="03:00" id="<? echo $daycal; ?>">
<?
if($calendar['time']=="03:00"){ 
?>
Booked
<? }else{ ?>
03:00
<? } ?>
</div>
<div class="hour" name="04:00" id="<? echo $daycal; ?>">
<?
if($calendar['time']=="04:00"){ 
?>
Booked
<? }else{ ?>
04:00
<? } ?>
</div>
<div class="hour" name="05:00" id="<? echo $daycal; ?>">
<?
if($calendar['time']=="05:00"){ 
?>
Booked
<? }else{ ?>
05:00
<? } ?>
</div>
<div class="hour" name="06:00" id="<? echo $daycal; ?>">
<?
if($calendar['time']=="06:00"){ 
?>
Booked
<? }else{ ?>
06:00
<? } ?>
</div>
<div class="hour" name="07:00" id="<? echo $daycal; ?>">
<?
if($calendar['time']=="07:00"){ 
?>
Booked
<? }else{ ?>
07:00
<? } ?>
</div>
<div class="hour" name="08:00" id="<? echo $daycal; ?>">
<?
if($calendar['time']=="08:00"){ 
?>
Booked
<? }else{ ?>
08:00
<? } ?>
</div>
<div class="hour" name="09:00" id="<? echo $daycal; ?>">
<?
if($calendar['time']=="09:00"){ 
?>
Booked
<? }else{ ?>
09:00
<? } ?>
</div>
<div class="hour" name="10:00" id="<? echo $daycal; ?>">
<?
if($calendar['time']=="10:00"){ 
?>
Booked
<? }else{ ?>
10:00
<? } ?>
</div>
<div class="hour" name="11:00" id="<? echo $daycal; ?>">
<?
if($calendar['time']=="11:00"){ 
?>
Booked
<? }else{ ?>
11:00
<? } ?>
</div>
<div class="hour" name="12:00" id="<? echo $daycal; ?>">
<?
if($calendar['time']=="12:00"){ 
?>
Booked
<? }else{ ?>
12:00
<? } ?>
</div>
<div class="hour" name="13:00" id="<? echo $daycal; ?>">
<?
if($calendar['time']=="13:00"){ 
?>
Booked
<? }else{ ?>
13:00
<? } ?>
</div>
<div class="hour" name="14:00" id="<? echo $daycal; ?>">
<?
if($calendar['time']=="14:00"){ 
?>
Booked
<? }else{ ?>
14:00
<? } ?>
</div>
<div class="hour" name="15:00" id="<? echo $daycal; ?>">
<?
if($calendar['time']=="15:00"){ 
?>
Booked
<? }else{ ?>
15:00
<? } ?>
</div>
<div class="hour" name="16:00" id="<? echo $daycal; ?>">
<?
if($calendar['time']=="16:00"){ 
?>
Booked
<? }else{ ?>
16:00
<? } ?>
</div>
<div class="hour" name="17:00" id="<? echo $daycal; ?>">
<?
if($calendar['time']=="17:00"){ 
?>
Booked
<? }else{ ?>
17:00
<? } ?>
</div>
<div class="hour" name="18:00" id="<? echo $daycal; ?>">
<?
if($calendar['time']=="18:00"){ 
?>
Booked
<? }else{ ?>
18:00
<? } ?>
</div>
<div class="hour" name="19:00" id="<? echo $daycal; ?>">
<?
if($calendar['time']=="19:00"){ 
?>
Booked
<? }else{ ?>
19:00
<? } ?>
</div>
<div class="hour" name="20:00" id="<? echo $daycal; ?>">
<?
if($calendar['time']=="20:00"){ 
?>
Booked
<? }else{ ?>
20:00
<? } ?>
</div>
<div class="hour" name="21:00" id="<? echo $daycal; ?>">
<?
if($calendar['time']=="21:00"){ 
?>
Booked
<? }else{ ?>
21:00
<? } ?>
</div>
<div class="hour" name="22:00" id="<? echo $daycal; ?>">
<?
if($calendar['time']=="22:00"){ 
?>
Booked
<? }else{ ?>
22:00
<? } ?>
</div>
<div class="hour" name="23:00" id="<? echo $daycal; ?>">
<?
if($calendar['time']=="23:00"){ 
?>
Booked
<? }else{ ?>
23:00
<? } ?>
</div>
</td></tr>
</table>

<!-- End Timetable -->
</td>
</tr>
<tr height="3"><td> </td></tr>
<?
}
?>
</tr>
<tr>
<form name="move_weeks" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="last_week" value="<? echo $week_start; ?>" />
<td colspan="7"><input type="submit" name="back_week" value="back_week" /><input type="submit" name="add_week" value="add_week" />
</td>
</form>
</tr>
</table>
</div>

So huge and useless code.. Why not to loop through and from 100 lines of code have only 10? 如此庞大且无用的代码。为什么不循环,而100行代码只有10行? I tried to reorganize your code. 我试图重新组织您的代码。 So finally i have this one: 所以最后我有了这个:

<div id="calendar">
<?php
    $week = date('d-m-Y', strtotime($_POST['last_week']));

    if(isset($_POST['add_week']))
        $new_week =  strtotime ( '+1 week' , strtotime ( $week ) ) ;
    if(isset($_POST['back_week']))
        $new_week =  strtotime ( '-1 week' , strtotime ( $week ) ) ;

    $new_week = date('d-m-Y', $new_week);

    if(!isset($_POST['add_week']) && !isset($_POST['back_week']))
    {
        $week_number = date("W");
        $year = date("Y");
    }
    else
    {
        $week_number = date("W", strtotime( $new_week));
        $year = date("Y", strtotime( $new_week));
    }

    $week_start = date('d-m-Y', strtotime($year."W".$week_number,0));
?>

<table name="week" width="100%" cellspacing="0" cellpadding="0" height="13">
    <tr>
<?
for($day=1; $day<=7; $day++)
{
?>
<tr>
    <td class="day">
        <?=$daycal = date('d M', strtotime($year."W".$week_number.$day))."";?>
    </td>

    <td width="3"> </td>
    <td>
    <!-- Timetable -->
    <table width="100%" cellspacing="0" cellpadding="0" height="13">
        <tr>
            <td>
            <?
                // Do not edit Below
                $cal = mysql_query("SELECT * FROM `calendar` WHERE `day`='$daycal' && `userid`='$globalid'")or die(mysql_error());
                $calendar = mysql_fetch_array($cal);

                for($cnt=0; $cnt<=24; $cnt++)
                { 
                    $hour = ($cnt<10?'0':'').$cnt.':00';
            ?>
                <div class="hour" name="<?=$hour?>" id="<? echo $daycal; ?>">
                    <?= ($calendar['time']==$hour) ? 'Booked' : $hour;  ?>
                </div>
            <? 
                } 
            ?>
            </td>
        </tr>
    </table>
    <!-- End Timetable -->
    </td>
</tr>
<tr height="3">
    <td> </td>
</tr>
<?
}
?>
</tr>
<tr>
    <form name="move_weeks" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
        <input type="hidden" name="last_week" value="<? echo $week_start; ?>" />
        <td colspan="7">
            <input type="submit" name="back_week" value="back_week" />
            <input type="submit" name="add_week" value="add_week" />
        </td>
    </form>
</tr>
</table>
</div>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM