私はphpとmysqlが初めてです。この画像のようにphpとmysqlで授業の時間割を用意しようとしています。
---------------------------------------
Days 9:30AM to 10:15am 10:15 AM to 11:00 AM
---------------------------------------
Monday Tamil English
---------------------------------------
Tuesday Maths
---------------------------------------
Wednesday
--------------------------------------- and so on
これは私のデータベーステーブル構造です...
DROP TABLE IF EXISTS `mas_batch`;
CREATE TABLE IF NOT EXISTS `mas_batch` (
`BatchId` int(10) NOT NULL AUTO_INCREMENT,
`CustomerId` int(10) NOT NULL DEFAULT '0',
`CourseId` int(10) NOT NULL DEFAULT '0',
`BatchName` varchar(100) NOT NULL DEFAULT '0',
`CDate` date DEFAULT NULL,
`CTime` time DEFAULT NULL,
`CUserId` int(10) NOT NULL DEFAULT '0',
`MDate` date DEFAULT NULL,
`MTime` time DEFAULT NULL,
`MUserId` int(10) NOT NULL DEFAULT '0',
`IsActive` int(1) DEFAULT '1',
PRIMARY KEY (`BatchId`),
KEY `FK_mas_batch_mas_course` (`CourseId`),
KEY `FK_mas_batch_mas_customer` (`CustomerId`),
CONSTRAINT `FK_mas_batch_mas_course` FOREIGN KEY (`CourseId`) REFERENCES `mas_course` (`CourseId`),
CONSTRAINT `FK_mas_batch_mas_customer` FOREIGN KEY (`CustomerId`) REFERENCES `mas_customer` (`CustomerId`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
DELETE FROM `mas_batch`;
INSERT INTO `mas_batch` (`BatchId`, `CustomerId`, `CourseId`, `BatchName`, `CDate`, `CTime`, `CUserId`, `MDate`, `MTime`, `MUserId`, `IsActive`) VALUES
(1, 1, 1, 'A', NULL, NULL, 0, NULL, NULL, 0, 1),
(2, 1, 1, 'B', NULL, NULL, 0, NULL, NULL, 0, 1),
(3, 1, 2, 'A', NULL, NULL, 0, NULL, NULL, 0, 1);
DROP TABLE IF EXISTS `mas_course`;
CREATE TABLE IF NOT EXISTS `mas_course` (
`CourseId` int(10) NOT NULL AUTO_INCREMENT,
`CustomerId` int(10) NOT NULL DEFAULT '0',
`CourseName` varchar(100) NOT NULL DEFAULT '0',
`CDate` date DEFAULT NULL,
`CTime` time DEFAULT NULL,
`CUserId` int(10) NOT NULL DEFAULT '0',
`MDate` date DEFAULT NULL,
`MTime` time DEFAULT NULL,
`MUserId` int(10) NOT NULL DEFAULT '0',
`IsActive` int(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`CourseId`),
KEY `FK_mas_course_mas_customer` (`CustomerId`),
CONSTRAINT `FK_mas_course_mas_customer` FOREIGN KEY (`CustomerId`) REFERENCES `mas_customer` (`CustomerId`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;
DELETE FROM `mas_course`;
INSERT INTO `mas_course` (`CourseId`, `CustomerId`, `CourseName`, `CDate`, `CTime`, `CUserId`, `MDate`, `MTime`, `MUserId`, `IsActive`) VALUES
(1, 1, '1st Std', '2014-03-26', NULL, 1, NULL, NULL, 0, 1),
(2, 1, '2nd Std', NULL, NULL, 0, NULL, NULL, 0, 1),
(3, 1, '4rd Std', NULL, NULL, 1, NULL, NULL, 0, 1),
(5, 1, '3rd Std', '2014-04-14', '18:50:02', 1, NULL, NULL, 0, 1),
(6, 1, '5th Std', '2014-04-14', '18:50:43', 1, NULL, NULL, 0, 1);
DROP TABLE IF EXISTS `mas_weekdays`;
CREATE TABLE IF NOT EXISTS `mas_weekdays` (
`WeekdaysId` int(10) NOT NULL AUTO_INCREMENT,
`Weekdays` varchar(50) NOT NULL DEFAULT '0',
`IsActive` int(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`WeekdaysId`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;
DELETE FROM `mas_weekdays`;
INSERT INTO `mas_weekdays` (`WeekdaysId`, `Weekdays`, `IsActive`) VALUES
(1, 'Sunday', 1),
(2, 'Monday', 1),
(3, 'Tuesday', 1),
(4, 'Wednesday', 1),
(5, 'Thursday', 1),
(6, 'Friday', 1),
(7, 'Saturday', 1);
/*!40000 ALTER TABLE `mas_weekdays` ENABLE KEYS */;
DROP TABLE IF EXISTS `set_academicyear`;
CREATE TABLE IF NOT EXISTS `set_academicyear` (
`AcademicYearId` int(10) NOT NULL AUTO_INCREMENT,
`CustomerId` int(10) NOT NULL DEFAULT '0',
`AcademicYear` varchar(100) NOT NULL DEFAULT '0',
`SDate` date DEFAULT NULL,
`EDate` date DEFAULT NULL,
`IsActive` int(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`AcademicYearId`),
KEY `FK_set_academicyear_mas_customer` (`CustomerId`),
CONSTRAINT `FK_set_academicyear_mas_customer` FOREIGN KEY (`CustomerId`) REFERENCES `mas_customer` (`CustomerId`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
DELETE FROM `set_academicyear`;
INSERT INTO `set_academicyear` (`AcademicYearId`, `CustomerId`, `AcademicYear`, `SDate`, `EDate`, `IsActive`) VALUES
(1, 1, '2013-2014', '2013-03-01', '2014-03-31', 0),
(2, 1, '2014-2015', '2014-04-01', '2015-03-31', 1);
DROP TABLE IF EXISTS `set_classtiming`;
CREATE TABLE IF NOT EXISTS `set_classtiming` (
`ClassTimingId` int(10) NOT NULL AUTO_INCREMENT,
`CustomerId` int(10) NOT NULL DEFAULT '0',
`ClassTimingName` varchar(100) NOT NULL DEFAULT '0',
`StartTime` time DEFAULT NULL,
`EndTime` time DEFAULT NULL,
`IsBreak` int(1) NOT NULL DEFAULT '0',
`IsActive` int(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`ClassTimingId`),
KEY `FK_set_classtiming_mas_customer` (`CustomerId`),
CONSTRAINT `FK_set_classtiming_mas_customer` FOREIGN KEY (`CustomerId`) REFERENCES `mas_customer` (`CustomerId`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;
DELETE FROM `set_classtiming`;
INSERT INTO `set_classtiming` (`ClassTimingId`, `CustomerId`, `ClassTimingName`, `StartTime`, `EndTime`, `IsBreak`, `IsActive`) VALUES
(1, 1, '1', '09:30:00', '10:15:00', 0, 1),
(2, 1, '2', '10:15:00', '11:00:00', 0, 1),
(3, 1, 'Break', '11:00:00', '11:15:00', 1, 1),
(4, 1, '3', '11:15:00', '12:00:00', 0, 1),
(5, 1, '4', '12:00:00', '12:45:00', 0, 1),
(6, 1, 'LUNCH', '12:45:00', '13:30:00', 1, 1);
DROP TABLE IF EXISTS `set_timetable`;
CREATE TABLE IF NOT EXISTS `set_timetable` (
`TimeTableId` int(10) NOT NULL AUTO_INCREMENT,
`CustomerId` int(10) NOT NULL DEFAULT '0',
`AcademicYearId` int(10) NOT NULL DEFAULT '0',
`CourseId` int(10) NOT NULL DEFAULT '0',
`BatchId` int(10) NOT NULL DEFAULT '0',
`WeekdaysId` int(10) NOT NULL DEFAULT '0',
`ClassTimingId` int(10) NOT NULL DEFAULT '0',
`SubjectId` int(10) NOT NULL DEFAULT '0',
`IsActive` int(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`TimeTableId`),
KEY `FK_set_timetable_mas_course` (`CourseId`),
KEY `FK_set_timetable_mas_batch` (`BatchId`),
KEY `FK_set_timetable_mas_customer` (`CustomerId`),
KEY `FK_set_timetable_set_academicyear` (`AcademicYearId`),
KEY `FK_set_timetable_set_classtiming` (`ClassTimingId`),
KEY `FK_set_timetable_mas_subject` (`SubjectId`),
KEY `FK_set_timetable_set_weekdays` (`WeekdaysId`),
CONSTRAINT `FK_set_timetable_mas_batch` FOREIGN KEY (`BatchId`) REFERENCES `mas_batch` (`BatchId`),
CONSTRAINT `FK_set_timetable_mas_course` FOREIGN KEY (`CourseId`) REFERENCES `mas_course` (`CourseId`),
CONSTRAINT `FK_set_timetable_mas_customer` FOREIGN KEY (`CustomerId`) REFERENCES `mas_customer` (`CustomerId`),
CONSTRAINT `FK_set_timetable_mas_subject` FOREIGN KEY (`SubjectId`) REFERENCES `mas_subject` (`SubjectId`),
CONSTRAINT `FK_set_timetable_set_academicyear` FOREIGN KEY (`AcademicYearId`) REFERENCES `set_academicyear` (`AcademicYearId`),
CONSTRAINT `FK_set_timetable_set_classtiming` FOREIGN KEY (`ClassTimingId`) REFERENCES `set_classtiming` (`ClassTimingId`),
CONSTRAINT `FK_set_timetable_set_weekdays` FOREIGN KEY (`WeekdaysId`) REFERENCES `set_weekdays` (`WeekdaysId`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;
DELETE FROM `set_timetable`;
INSERT INTO `set_timetable` (`TimeTableId`, `CustomerId`, `AcademicYearId`, `CourseId`, `BatchId`, `WeekdaysId`, `ClassTimingId`, `SubjectId`, `IsActive`) VALUES
(3, 1, 1, 1, 1, 10, 1, 1, 1),
(4, 1, 1, 1, 1, 11, 2, 2, 1),
(5, 1, 1, 1, 1, 12, 1, 1, 1),
(6, 1, 1, 1, 1, 13, 1, 2, 1),
(7, 1, 1, 1, 1, 14, 2, 1, 1),
(8, 1, 1, 1, 1, 10, 2, 2, 1);
DROP TABLE IF EXISTS `set_weekdays`;
CREATE TABLE IF NOT EXISTS `set_weekdays` (
`WeekdaysId` int(10) NOT NULL AUTO_INCREMENT,
`CustomerId` int(10) NOT NULL DEFAULT '0',
`Mas_WeekdaysId` int(2) NOT NULL DEFAULT '0',
`IsActive` int(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`WeekdaysId`),
KEY `FK_set_weekdays_mas_customer` (`CustomerId`),
KEY `FK_set_weekdays_mas_weekdays` (`Mas_WeekdaysId`),
CONSTRAINT `FK_set_weekdays_mas_customer` FOREIGN KEY (`CustomerId`) REFERENCES `mas_customer` (`CustomerId`),
CONSTRAINT `FK_set_weekdays_mas_weekdays` FOREIGN KEY (`Mas_WeekdaysId`) REFERENCES `mas_weekdays` (`WeekdaysId`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=latin1;
DELETE FROM `set_weekdays`;
INSERT INTO `set_weekdays` (`WeekdaysId`, `CustomerId`, `Mas_WeekdaysId`, `IsActive`) VALUES
(9, 1, 1, 0),
(10, 1, 2, 1),
(11, 1, 3, 1),
(12, 1, 4, 1),
(13, 1, 5, 1),
(14, 1, 6, 1),
(15, 1, 7, 0);
クラスの時間割を作成するのを手伝ってください...
$CustomerId = 1;
$AcademicYearId = 1;
$CourseId = 1;
$BatchId = 1;
$sql_tt = "SELECT * from set_weekdays where IsActive=1";
$res_tt = mysql_query($sql_tt);
if(mysql_num_rows($res_tt))
{
echo '<table id="listing_items" width="auto" border="1" cellpadding="2" cellspacing="2" align="center">';
echo '<tr>';
echo '<th>Days</th>';
$sql_classtime = "select * from set_classtiming where IsActive=1";
$res_classtime = mysql_query($sql_classtime);
if(mysql_num_rows($res_classtime)>0)
{
while($row_classtt = mysql_fetch_assoc($res_classtime))
{
if($row_classtt['IsBreak'] == 0)
{
echo '<th>'.time_from_db($row_classtt['StartTime']).'<br />'.time_from_db($row_classtt['EndTime']).'</th>';
}
else
{
echo '<th>'.$row_classtt['ClassTimingName'].'</th>';
}
}
}
echo '</tr>';
while($row_tt = mysql_fetch_assoc($res_tt))
{
echo '<tr>';
echo '<th>'.column_name("Weekdays", "mas_weekdays", "WeekdaysId", $row_tt['Mas_WeekdaysId']).'</th>';
$sql_classtime1 = "select * from set_classtiming where IsActive=1 group by ClassTimingId";
$res_classtime1 = mysql_query($sql_classtime1);
if(mysql_num_rows($res_classtime1) > 0)
{
while($row_classtt1 = mysql_fetch_assoc($res_classtime1))
{
$sql_time = "select * from set_timetable where CustomerId=".$CustomerId." AND AcademicYearId=".$AcademicYearId." AND CourseId=".$CourseId." AND BatchId=".$BatchId;
$res_time = mysql_query($sql_time);
if(mysql_num_rows($res_time) > 0)
{
while($row_time = mysql_fetch_assoc($res_time))
{
if(($row_time['ClassTimingId'] == $row_classtt1['ClassTimingId']))
{
if($row_classtt1['IsBreak'] == 1)
{
echo '<td> </td>';
}
else
{
if(($row_time['WeekdaysId'] == $row_tt['WeekdaysId']))
{
echo '<td>'.column_name("SubjectName", "mas_subject", "SubjectId", $row_time['SubjectId']).'</td>';
}
else
{
echo '<td> </td>';
}
}
}
}
}
}
}
echo '</tr>';
}
echo '</table>';
}
これは、タイムテーブルを生成するための私の完全なコーディングです....上記で、データベースにデータを貼り付けました。親切に必要なことをしてください...
前もって感謝します。