我试图读取我的 MySQL 数据库的数据,我创建了完整的日历并在日历上显示了事件。但是,它无法从我的 MySQL 数据库中检索数据。
第一个php代码:
<?php require_once('conn.php'); ?>
<?php $maxRows_RsCourse = 1000000;
$pageNum_RsCourse = 0;
if (isset($_GET['pageNum_RsCourse'])) {
$pageNum_RsCourse = $_GET['pageNum_RsCourse'];
}
$startRow_RsCourse = $pageNum_RsCourse * $maxRows_RsCourse;
mysql_select_db($database_conn, $conn);
$query_RsCourse = "SELECT * FROM tbl_course ORDER BY tcid ASC";
$query_limit_RsCourse = sprintf("%s LIMIT %d, %d", $query_RsCourse, $startRow_RsCourse, $maxRows_RsCourse);
$RsCourse = mysql_query($query_limit_RsCourse, $conn) or die(mysql_error());
$row_RsCourse = mysql_fetch_assoc($RsCourse);
if (isset($_GET['totalRows_RsCourse'])) {
$totalRows_RsCourse = $_GET['totalRows_RsCourse'];
} else {
$all_RsCourse = mysql_query($query_RsCourse);
$totalRows_RsCourse = mysql_num_rows($all_RsCourse);
}
$totalPages_RsCourse = ceil($totalRows_RsCourse/$maxRows_RsCourse)-1;
?>
<?php
$tbl_name="tbl_course"; // Table name
$totalcount = 0;
// Connect to server and select database.
mysql_connect("$hostname_conn", "$username_conn", "$password_conn")or die("cannot connect server ");
mysql_select_db("$database_conn")or die("unable to connect");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){
// echo "<table><tr>";
// echo "<td>" . $rows['id'] . "</td><td>" . $rows['title'] . "</td><td>" . $rows['start'] . "</td><td>" . $rows['end'] . "</td><td>" . $rows['url'] . "</td><td>" . $rows['allDay'];
// echo "</td></tr></table>";
$event[$totalcount]['tcid']=$rows['tcid'];
$event[$totalcount]['courseid']=$rows['courseid'];
$event[$totalcount]['coursename']=$rows['coursename'];
$event[$totalcount]['startdate']=$rows['startdate'];
$event[$totalcount]['starttime']=$rows['starttime'];
$event[$totalcount]['enddate']=$rows['enddate'];
$event[$totalcount]['endtime']=$rows['endtime'];
$event[$totalcount]['allday']=$rows['allday'];
$totalcount++;
}
for ($i=0; $i < $totalcount; $i++)
{
$tmp1 = explode("-",$event[$i]['startdate']);
$tmp2 = explode(":",$event[$i]['starttime']);
// 0 = hour, 1 = minutes, 2 = seconds,
$x = 0;
foreach ($tmp1 as $date_values_1)
{
$event_start_date[$i][$x] = $date_values_1;
$x++;
}
$y = 0;
foreach ($tmp2 as $time_values_1)
{
$event_start_time[$i][$y] = $time_values_1;
$y++;
}
$tmp3 = explode("-",$event[$i]['enddate']);
$tmp4 = explode(":",$event[$i]['endtime']);
$a = 0;
foreach ($tmp3 as $date_values_2)
{
$event_end_date[$i][$a] = $date_values_2;
$a++;
}
$b = 0;
foreach ($tmp4 as $time_values_2)
{
$event_end_time[$i][$b] = $time_values_2;
$b++;
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0046)http://localhost/calendar/demos/db_display.php -->
<HTML><HEAD>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type>
<link href='css/fullcalendar.css' rel='stylesheet' />
<script src='js/jquery-1.9.1.min.js'></script>
<script src='js/jquery-ui-1.10.2.custom.min.js'></script>
<script src='js/fullcalendar.min.js'></script>
<SCRIPT>
$(document).ready(function() {
var start_year = new Array(<?php $totalcount?>);
var start_month = new Array(<?php $totalcount?>);
var start_day = new Array(<?php $totalcount?>);
var end_year =new Array(<?php $totalcount?>);
var end_month =new Array(<?php $totalcount?>);
var end_day =new Array(<?php $totalcount?>);
var start_hour =new Array(<?php $totalcount?>);
var start_mins =new Array(<?php $totalcount?>);
var end_hour =new Array(<?php $totalcount?>);
var end_mins =new Array(<?php $totalcount?>);
<?php
$k = 0;
for ($k=0; $k < $totalcount; $k++) {?>
start_year[<?php echo $k?>] =<?php echo $event_start_date[$k][0] ?>;
start_month[<?php echo $k?>] =<?php echo $event_start_date[$k][1] ?>;
start_day[<?php echo $k?>] =<?php echo $event_start_date[$k][2]?>;
end_year[<?php echo $k?>] =<?php echo $event_end_date[$k][0]?>;
end_month[<?php echo $k?>] =<?php echo $event_end_date[$k][1]?>;
end_day[<?php echo $k?>] =<?php echo $event_end_date[$k][2]?>;
start_hour[<?php echo $k?>] =<?php echo $event_start_time[$k][0] ?>;
start_mins[<?php echo $k?>] =<?php echo $event_start_time[$k][1] ?>;
end_hour[<?php echo $k?>] =<?php echo $event_end_time[$k][0]?>;
end_mins[<?php echo $k?>] =<?php echo $event_end_time[$k][1]?>;
<?php } ?>
var calendar = $('#calendar').fullCalendar({
editable: false,
events: [
<?php $j = 0;
for ($j=0; $j < $totalcount; $j++)
{
?>
<?php
if ($event[$j]['allday'] == 0){?>
{ title: '<?php echo $event[$j]['courseid'];?> <?php echo $event[$j]['coursename'];?>',
start: new Date(start_year[<?php echo $j?>],start_month[<?php echo $j?>]-1,start_day[<?php echo $j?>],start_hour[<?php echo $j?>],start_mins[<?php echo $j?>]),
end: new Date(end_year[<?php echo $j?>],end_month[<?php echo $j?>]-1,end_day[<?php echo $j?>],end_hour[<?php echo $j?>],end_mins[<?php echo $j?>]) , url: 'mg_course.php?courseid=<?php echo $event[$j]['courseid']; ?>'
/*
end: new Date(end_year[<?php echo $j?>],end_month[<?php echo $j?>]-1,end_day[<?php echo $j?>],end_hour[<?php echo $j?>],end_mins[<?php echo $j?>]) , url: 'mg_course.php?courseid=<?php echo $_GET['courseid']; ?>'
*/
},
<?php } ?>
<?php if ($event[$j]['allday'] == 1) {?>
{ title: '<?php echo $event[$j]['courseid'];?> <?php echo $event[$j]['coursename'];?>',
start: new Date(start_year[<?php echo $j?>],start_month[<?php echo $j?>]-1,start_day[<?php echo $j?>],start_hour[<?php echo $j?>],start_mins[<?php echo $j?>]),
end: new Date(end_year[<?php echo $j?>],end_month[<?php echo $j?>]-1,end_day[<?php echo $j?>],end_hour[<?php echo $j?>],end_mins[<?php echo $j?>]), url: 'mg_course.php?courseid=<?php echo $event[$j]['courseid']; ?>',
/*
end: new Date(end_year[<?php echo $j?>],end_month[<?php echo $j?>]-1,end_day[<?php echo $j?>],end_hour[<?php echo $j?>],end_mins[<?php echo $j?>]), url: 'mg_course.php?courseid=<?php echo $_GET['courseid']; ?>',
*/
allDay: 'false'
},
<?php } ?>
<?php }?>
{}
]
});
});
</SCRIPT>
<STYLE>BODY {
TEXT-ALIGN: center; MARGIN-TOP: 40px; FONT-FAMILY: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif; FONT-SIZE: 14px
}
#calendar {
MARGIN: 0px auto; WIDTH: 900px
}
</STYLE>
<META name=GENERATOR content="MSHTML 8.00.6001.19412"></HEAD>
<BODY>
<DIV id=calendar></DIV></BODY></HTML>
这是显示事件详细信息php:
<?php require_once('conn.php'); ?>
<?php
session_start();
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}
?>
<?php
$totalRows_RsEnrol = 0;
if ( isset($_POST['courseid']) ) {
$_GET['courseid'] = $_POST['courseid'];
$_GET['courseid'] = $_GET['courseid'] * 1;
if (is_integer($_GET['courseid']) ) {
$maxRows_RsEnrol = 10000;
$pageNum_RsEnrol = 0;
if (isset($_GET['pageNum_RsEnrol'])) {
$pageNum_RsEnrol = $_GET['pageNum_RsEnrol'];
}
$startRow_RsEnrol = $pageNum_RsEnrol * $maxRows_RsEnrol;
mysql_select_db($database_conn, $conn);
$query_RsEnrol = "SELECT * FROM 'tbl_enroll' WHERE 'tbl_enroll'.'courseid' = '".$_GET['courseid']."'";
//$query_RsEnrol = sprintf("SELECT erid, courseid, staffid FROM tbl_enroll WHERE courseid = %s ORDER BY staffid ASC", $_GET['courseid']);
$query_limit_RsEnrol = sprintf("%s LIMIT %d, %d", $query_RsEnrol, $startRow_RsEnrol, $maxRows_RsEnrol);
$RsEnrol = mysql_query($query_limit_RsEnrol, $conn) or die(mysql_error());
$row_RsEnrol = mysql_fetch_assoc($RsEnrol);
if (isset($_GET['totalRows_RsEnrol'])) {
$totalRows_RsEnrol = $_GET['totalRows_RsEnrol'];
} else {
$all_RsEnrol = mysql_query($query_RsEnrol);
$totalRows_RsEnrol = mysql_num_rows($all_RsEnrol);
}
$totalPages_RsEnrol = ceil($totalRows_RsEnrol/$maxRows_RsEnrol)-1;
} else { $totalRows_RsEnrol = 0;}
}
/******************************************************************************************************/
elseif (isset($_GET['courseid']) && !empty($_GET['courseid']) ) {
$_GET['courseid'] = $_GET['courseid']*1;
if (is_integer($_GET['courseid'])){
$maxRows_RsEnrol = 1000000;
$pageNum_RsEnrol = 0;
if (isset($_GET['pageNum_RsEnrol'])) {
$pageNum_RsEnrol = $_GET['pageNum_RsEnrol'];
}
$startRow_RsEnrol = $pageNum_RsEnrol * $maxRows_RsEnrol;
mysql_select_db($database_conn, $conn);
$query_RsEnrol = sprintf("SELECT * FROM tbl_enroll WHERE courseid IN ( SELECT courseid FROM tbl_course WHERE courseid = %s) ORDER BY erid ASC", $_GET['courseid']);
//$query_RsEnrol = sprintf("SELECT erid, courseid, staffid FROM tbl_enroll WHERE courseid=%s ORDER BY staffid ASC", $_GET['courseid']);
$query_limit_RsEnrol = sprintf("%s LIMIT %d, %d", $query_RsEnrol, $startRow_RsEnrol, $maxRows_RsEnrol);
$RsEnrol = mysql_query($query_limit_RsEnrol, $conn) or die(mysql_error());
$row_RsEnrol = mysql_fetch_assoc($RsEnrol);
if (isset($_GET['totalRows_RsEnrol'])) {
$totalRows_RsEnrol = $_GET['totalRows_RsEnrol'];
} else {
$all_RsEnrol = mysql_query($query_RsEnrol);
$totalRows_RsEnrol = mysql_num_rows($all_RsEnrol);
}
$totalPages_RsEnrol = ceil($totalRows_RsEnrol/$maxRows_RsEnrol)-1;
} else {$totalRows_RsEnrol=0;}
}
?>
<!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">
<link href="../../css/style_new.css" rel="stylesheet" type="text/css" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<br />
<table width="322" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="171"><img src="../../Images/logo.gif" width="144" height="34"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" align="center" ><h2>Training Program</h2></td>
</tr>
</table>
<div class="containers" align=">
<div class="header">
<p align="center" class="style2">Enrolment</p>
<h5 class="../css/new_style.css" align="left">
<table align="center" width="116%" border="0" cellpadding="0" cellspacing="2" >
<tr align="center" bgcolor="#CCCCCC" >
<td width="16%">Enrolment ID</td>
<td width="50%">Course ID</td>
<td width="14%">Staff ID</td>
<td width="10%"> </td>
<td width="10%"> </td>
</tr>
<tr align="center" bgcolor="#dfdfdf" >
<td><?php echo $row_RsEnrol['erid']; ?></td>
<td align="left"> <?php echo $row_RsEnrol['courseid']; ?></td>
<td><?php echo $row_RsEnrol['staffid']; ?></td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>
它无法过滤日历上的数据。
我非常感谢您的帮助。