2014-01-12 54 views
0

我已经做了一个php事件日历这是工作,我可以在几个月之间切换,但是当我添加一个事件到我的数据库它不会出现在我的日历上。最受赞赏的任何帮助。事件不会出现在php日历

代码: 显示calendar.php

<html> 
<head> 
<link href="calstyle.css" rel="stylesheet" type="text/css" media="all" /> 
<script language="JavaScript" type="text/javascript"> 
function initialCalendar(){ 
    var hr = new XMLHttpRequest(); 
    var url = "calendar_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 = "calendar_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 = "calendar_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 type="text/javascript"> 
function overlay() { 
    el = document.getElementById("overlay"); 
    el.style.display = (el.style.display == "block") ? "none" : "block"; 
    el. = document.getElementById("events"); 
    el.style.display = (el.style.display == "block") ? "none" : "block"; 
    el. = document.getElementById("eventsBody"); 
    el.style.display = (el.style.display == "block") ? "none" : "block"; 
} 
</script> 
<script language="javascript" type="text/javascript"> 
function show_details(theId) { 
    var deets =)theId.id); 
    el = document.getElementById("overlay"); 
    el.style.display = (el.style.display == "block") ? "none" : "block"; 
    el. = document.getElementById("events"); 
    el.style.display = (el.style.display == "block") ? "none" : "block"; 
    var hr = new XMLHttpRequest(); 
    var url = "events.php"; 
    var vars = "deets="+deets; 
    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("events").innerHTML = return_data; 
     } 
    } 
    hr.send(vars); 
    document.get ElementById("events").innerHTML = "processing..."; 
} 
</script> 
</head> 
<body onload="initialCalendar();"> 
<div id="showCalendar"> </div> 
<div id="overlay"> 
    <div id="events"></div> 
</div> 
</body> 
</html> 

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="calendar_wrap">'; 
echo '<div class="title_bar">'; 
echo '<div class="previous_month"><input name="button" type="submit" value="Previous Month" onClick="javascript:last_month();"></div>'; 
echo '<div class="show_month">' . date('F', mktime(0, 0, 0, $showmonth)) . ' ' . $showyear . '</div>'; 
echo '<div class="next_month"><input name="button" type="submit" value="Next Month" onClick="javascript:next_month();"></div>'; 
echo '</div>'; 

echo '<div class="week_days">'; 
echo '<div class="days_of_the_week">Sun</div>'; 
echo '<div class="days_of_the_week">Mon</div>'; 
echo '<div class="days_of_the_week">Tues</div>'; 
echo '<div class="days_of_the_week">Wed</div>'; 
echo '<div class="days_of_the_week">Thur</div>'; 
echo '<div class="days_of_the_week">Fri</div>'; 
echo '<div class="days_of_the_week">Sat</div>'; 
echo '<div class="clear"></div>'; 
echo '</div>'; 

if ($pre_days != 0) { 
    for($i=1; $i<=$pre_days; $i++) { 
     echo '<div class="non_cal_day"></div>'; 
    } 
} 
include ("connect.php"); 
for ($i=1; $i<= $day_count; $i++) { 
    $date = $i.'/'.$showmonth.'/'.$showyear; 
$query = "Select id FROM events WHERE evDate = '$date'"; 
$num_rows = 0; 
if($result = mysql_query($query)) { 
    $num_rows = mysql_num_rows($result); 
} 
    if($num_rows > 0) { 
     $event = "<input name='$date' type='submit' value='Details' id='$date' 
onClick='javascript:show_details(this);'>"; 
    } 
    echo '<div class="cal_day">'; 
    echo '<div class="day_heading">' . $i . '</div>'; 
    if($num_rows != 0) { echo "<div class='openings'><br/>" . $event . "</div>";} 
    echo '</div>'; 
} 

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

events.php

<?php 
$deets = $_POST['deets']; 
$deets = preg_replace('#[^0-9/]#i', '', $deets); 

include ("connect.php"); 

$events = ''; 
$query = mysql_query('SELECT description FROM events WHERE evdate ="'.$deets.'"'); 
$num_rows= mysql_num_rows($query); 
if ($num_rows > 0) { 
    $events.= '<div id="eventsControl"><button onMouseDown="overlay()">Close</button><br /><b> ' . $deets . '</b><br /><br /></div>'; 

    while($row= mysql_fetch_array($query)) { 
     $desc = $row['description']; 
     $events .='<div id="eventsBody"> . $desc .'<br /><hr><br /></div>'; 
    } 
} 
echo $events; 
?> 

connect.php

<?php 
$con=mysqli_connect("localhost","root","","Familease"); 
if (mysqli_connect_errno($con)) 
    { 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
    } 
?> 

加上一个样式表应该工作正常。很抱歉的大量代码转储

回答

0

你下面的代码显示了一些语法错误

while($row= mysql_fetch_array($query)) { 
     $desc = $row['description']; 
     $events .='<div id="eventsBody"> . $desc .'<br /><hr><br /></div>'; 
    } 

while($row= mysql_fetch_array($query)) { 
     $desc = $row['description']; 
     $events .='<div id="eventsBody">'.$desc .'<br /><hr><br /></div>'; 
    } 
+0

仍然没有工作,别的什么吗? – user3181157

+0

这就是问题的一部分,你可以检查你的查询是否返回任何数据? –