Javascript 日历未显示正确的成员事件
我有一个有多个成员的网站,我希望每个成员都有自己的日历。 我找到了一个构建和事件日历witch的教程,它工作得很好,但是我在尝试将事件显示在正确的日历上时遇到了困难,要么每个人都可以看到数据库中的所有事件,要么没有人可以看到任何事件 我的代码如下 calendar_start.phpJavascript 日历未显示正确的成员事件,javascript,php,ajax,mysqli,Javascript,Php,Ajax,Mysqli,我有一个有多个成员的网站,我希望每个成员都有自己的日历。 我找到了一个构建和事件日历witch的教程,它工作得很好,但是我在尝试将事件显示在正确的日历上时遇到了困难,要么每个人都可以看到数据库中的所有事件,要么没有人可以看到任何事件 我的代码如下 calendar_start.php <?php $showmonth = $_POST['showmonth']; $showyear = $_POST['showyear']; $showmonth = preg_replace('#[^
<?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>';
?>
在您的calendar\u 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'];
//show_calendar.php中的Ajax请求示例
var hr=新的XMLHttpRequest();
var url=“calender\u start.php”;
var currentTime=新日期();
var month=currentTime.getMonth()+1;
var year=currentTime.getFullYear();
showmonth=月份;
showyear=year;
var vars=“showmonth=“+showmonth+”&showyear=“+showyear+”&squadid=“;
hr.open(“POST”,url,true);
hr.setRequestHeader(“内容类型”、“应用程序/x-www-form-urlencoded”);
hr.onreadystatechange=函数(){
如果(hr.readyState==4&&hr.status==200){
var return_data=hr.responseText;
document.getElementById(“showCalendar”).innerHTML=返回\u数据;
}
}
人力资源发送(vars);
document.getElementById(“showCalendar”).innerHTML=“处理…”;
//在calendar_start.php中获取var添加此行
$squadid=$_POST['squadid'];
希望这对你有帮助。
干杯 嗨,格鲁吉亚人,我已经尝试过你的建议,但不幸的是,仍然无法使其发挥作用。我把$squadid=$_POST['squadid']放在这里对吗;在calendar_start.php中?首先,从ajax发送它,然后发送它;what’你的意思是通过ajax发送吗?你是说这行:var vars=“showmonth=“+showmonth+”&showyear=“+showyear+”&squadid=“;如果是这样,我已经添加了这个,但仍然无法看到事件。我还缺什么吗?当我遇到这些小麻烦的时候,这通常是很明显的。谢谢你的帮助
//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'];