【问题标题】:calendar not showing correct members events日历未显示正确的成员事件
【发布时间】:2013-10-07 22:13:29
【问题描述】:

我有一个包含多个成员的网站,我希望每个成员都有自己的日历。 我找到了一个教程来构建和事件日历女巫工作正常,但我无法尝试让事件显示在正确的日历上,每个人都可以看到数据库中的所有事件,或者没有人可以看到任何事件。

我的代码如下

calendar_start.php

<?php 

$showmonth = $_POST['showmonth'];
$showyear = $_POST['showyear'];
$showmonth = preg_replace('#[^0-9]#i', '', $showmonth);
$showyear = preg_replace('#[^0-9]#i', '', $showyear);


$day_count = cal_days_in_month(CAL_GREGORIAN, $showmonth, $showyear);
$pre_days = date('w', mktime(0,0,0, $showmonth, 1, $showyear));
$post_days = (6 - (date('w', mktime(0,0,0, $showmonth, $day_count, $showyear))));

echo '<div id="calender_wrap">';

echo '<div class="title_bar">';
echo '<div class="previouse_month"><input name="myBtn" type="submit" value="Previouse Month" onclick="javascript:last_month();"></div';
echo '<div class="show_month">' . $showmonth . '/' . $showyear . '</div>';
echo '<div class="next_month"><input name="myBtn" type="submit" value="Next Month" onclick="javascript:next_month();"></div>';
echo '</div>';

echo '<div class="week_days">';
echo '<div class="days_of_week">Sunday</div>';
echo '<div class="days_of_week">Monday</div>';
echo '<div class="days_of_week">Tuesday</div>';
echo '<div class="days_of_week">Wednesday</div>';
echo '<div class="days_of_week">Thursday</div>';
echo '<div class="days_of_week">Friday</div>';
echo '<div class="days_of_week">saturday</div>';
echo '<div class="clear"></div>';
echo '</div>';

/* Previouse Month filler Days */
if ($pre_days != 0) {
    for($i = 1; $i<=$pre_days; $i++) {
        echo '<div class="non_cal_day"></div>';
    }
}

/*Current Month filler Days */
include("scripts/connect_to_mysql.php");
for($i = 1; $i<= $day_count; $i++) {
    // get event logic

    $date = $i . '/' . $showmonth . '/' . $showyear;
    $query = "SELECT * FROM occurrences WHERE cid ='$squadid' AND start_date ='$date' ";
    $cal = mysqli_query($db_conx, $query);
    $num_rows = mysqli_num_rows($cal);
        if($num_rows > 0) {
            $event= '<a href="view_events.php"><h3 class="event_here">Events Here</h3></a>';
            }
        //end get event logic

    echo '<div class="cal_day">';
    echo '<div class="day_heading">' . $i . ' <a href="add_event.php"><div class="add_event"></div></a></div><br/>';
    if($num_rows != 0) { echo $event;}
    echo '</div>';
}

/* Next month filler days */
if ($post_days != 0) {
    for($i = 1; $i<=$post_days; $i++) {
        echo '<div class="non_cal_day"></div>';
    }
}

echo '</div>';

?>

show_calendar.php

<?php 
// Start_session, check if user is logged in or not, and connect to the database all in one included file
include_once("scripts/checkuserlog.php");
// Include the class files for auto making links out of full URLs and for Time Ago date formatting
include_once("wi_class_files/autoMakeLinks.php");
include_once ("wi_class_files/agoTimeFormat.php");
// Create the two new objects before we can use them below in this script
$activeLinkObject = new autoActiveLink;
$myObject = new convertToAgo;

// ------- ESTABLISH THE PAGE ID ACCORDING TO CONDITIONS ---------
$squadid = "";
if (isset($_GET['pid'])){ $squadid = $_GET['pid'];};
// ------- END ESTABLISH THE PAGE ID ACCORDING TO CONDITIONS ---------

//-------- GET EVENTS FROM TABLE-------------------------------------

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Calender</title>
<link href="style/calCss.css" rel="stylesheet" type="text/css" media="all" />
<link href="style/main.css" rel="stylesheet" type="text/css" />
<link rel="icon" href="logoicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="logoicon.ico" type="image/x-icon" />
<script language="javascript" type="text/javascript">
function initialCalendar() {
    var hr = new XMLHttpRequest();
    var url = "calender_start.php";
    var currentTime = new Date();
    var month = currentTime.getMonth() + 1;
    var year = currentTime.getFullYear();
    showmonth = month;
    showyear = year;
    var vars = "showmonth="+showmonth+"&showyear="+showyear;
    hr.open("POST", url, true);
    hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    hr.onreadystatechange = function() {
        if(hr.readyState == 4 && hr.status == 200) {
            var return_data = hr.responseText;
            document.getElementById("showCalendar") .innerHTML = return_data;
        }
    }
    hr.send(vars);
    document.getElementById("showCalendar") .innerHTML = "processing...";
}
</script>
<script language="javascript" type="text/javascript">
function next_month() {
    var nextmonth = showmonth + 1;
    if(nextmonth > 12) {
        nextmonth = 1;
        showyear = showyear + 1;
    }
    showmonth = nextmonth;
    var hr = new XMLHttpRequest();
    var url = "calender_start.php";
    var vars = "showmonth="+showmonth+"&showyear="+showyear;
    hr.open("POST", url, true);
    hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    hr.onreadystatechange = function() {
        if(hr.readyState == 4 && hr.status == 200) {
            var return_data = hr.responseText;
            document.getElementById("showCalendar").innerHTML = return_data;
        }
    }
    hr.send(vars);
    document.getElementById("showCalendar").innerHTML = "processing...";
}
</script>
<script language="JavaScript" type="text/javascript">
function last_month() {
    var lastmonth = showmonth - 1;
    if(lastmonth < 1) {
        lastmonth = 12;
        showyear = showyear - 1;
    }
    showmonth = lastmonth;
    var hr = new XMLHttpRequest();
    var url = "calender_start.php";
    var vars = "showmonth="+showmonth+"&showyear="+showyear;
    hr.open("POST", url, true);
    hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    hr.onreadystatechange = function() {
        if(hr.readyState == 4 && hr.status == 200) {
            var return_data = hr.responseText;
            document.getElementById("showCalendar").innerHTML = return_data;
        }
    }
    hr.send(vars);
    document.getElementById("showCalendar").innerHTML = "processing...";
}
</script>
</head>

<body onload="initialCalendar();">
<?php include_once "header_template.php"; ?>
<table class="mainBodyTable" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="740" valign="top"><div><?php include_once "leaderBoardAd.php"; ?></div><br />
      <table width="90%" align="center" cellpadding="6">
        <tr>
          <td>
          <div id="showCalendar"></div>
          </td>
        </tr>
      </table></td>
    <td width="160" valign="top"><?php include_once "right_AD_template.php"; ?></td>
  </tr>
</table>
<?php include_once "footer_template.php"; ?>

</body>
</html>

目前,如果我从 calendar_start.php 中的 $query 中删除 cid ='$squadid',您可以看到数据库中的所有事件,但网站上的每个成员也可以看到它们。

在我的表格中,cid 应该代表日历 ID,即。成员有自己的日历,但我不知道哪里出错了。

我希望我已经对此进行了充分的解释,但如果您需要更多信息,请告诉我。

非常感谢

【问题讨论】:

    标签: javascript php ajax mysqli


    【解决方案1】:

    在您的 calendar_start.php(即由您的 ajax 请求触发的文件)中,var $squadid 为空。您需要将 $squadid 从 show_calendar.php 发送到 calendar_start.php 抛出您的 ajax 请求。

    这是一个例子:

      //Ajax request example from show_calendar.php
        var hr = new XMLHttpRequest();
        var url = "calender_start.php";
        var currentTime = new Date();
        var month = currentTime.getMonth() + 1;
        var year = currentTime.getFullYear();
        showmonth = month;
        showyear = year;
        var vars = "showmonth="+showmonth+"&showyear="+showyear+"&squadid=<?= $squadid; ?>";
        hr.open("POST", url, true);
        hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        hr.onreadystatechange = function() {
            if(hr.readyState == 4 && hr.status == 200) {
                var return_data = hr.responseText;
                document.getElementById("showCalendar") .innerHTML = return_data;
            }
        }
        hr.send(vars);
        document.getElementById("showCalendar") .innerHTML = "processing...";
    
    
        //Get the var in calendar_start.php add this line
        $squadid = $_POST['squadid'];
    

    希望这对你 m8 有所帮助。 干杯!

    【讨论】:

    • 您好,Georgian,我已经尝试了您的建议,但不幸的是仍然无法使其正常工作。我是否正确放置 $squadid = $_POST['squadid'];进入calendar_start.php?
    • 首先,从 ajax 发送它,然后它;你所做的就是正确的
    • 当您的意思是通过 ajax 发送时,您的意思是这一行: var vars = "showmonth="+showmonth+"&showyear="+showyear+"&squadid== $squadid; ?>";如果是这样,我已经添加了这个,但仍然看不到事件。我还想念别的吗?当我陷入这些小习惯时,它通常会很明显,哈哈。感谢您到目前为止的帮助
    猜你喜欢
    • 2014-12-20
    • 1970-01-01
    • 2020-11-28
    • 1970-01-01
    • 2012-08-21
    • 1970-01-01
    • 2022-10-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多