<?php require_once('Connections/dbconnect.php'); ?>
<?php
$c=$_GET['Class'];
$s=$_GET['Section'];
$f=$_GET['fmonth'];
$t=$_GET['tmonth'];
$count=1;
mysql_select_db($database_dbconnect, $dbconnect);
$query_classwise = "SELECT Name_of_Student, Roll_no, Section,
GROUP_CONCAT(if(DAY(`Date`) = 1, `Status`, NULL)) AS 'day1',
GROUP_CONCAT(if(DAY(`Date`) = 2, `Status`, NULL)) AS 'day2',
GROUP_CONCAT(if(DAY(`Date`) = 3, `Status`, NULL)) AS 'day3',
GROUP_CONCAT(if(DAY(`Date`) = 4, `Status`, NULL)) AS 'day4',
GROUP_CONCAT(if(DAY(`Date`) = 5, `Status`, NULL)) AS 'day5',
GROUP_CONCAT(if(DAY(`Date`) = 6, `Status`, NULL)) AS 'day6',
GROUP_CONCAT(if(DAY(`Date`) = 7, `Status`, NULL)) AS 'day7',
GROUP_CONCAT(if(DAY(`Date`) = 8, `Status`, NULL)) AS 'day8',
GROUP_CONCAT(if(DAY(`Date`) = 9, `Status`, NULL)) AS 'day9',
GROUP_CONCAT(if(DAY(`Date`) = 10, `Status`, NULL)) AS'day10',
GROUP_CONCAT(if(DAY(`Date`) = 11, `Status`, NULL)) AS 'day11',
GROUP_CONCAT(if(DAY(`Date`) = 12, `Status`, NULL)) AS 'day12',
GROUP_CONCAT(if(DAY(`Date`) = 13, `Status`, NULL)) AS 'day13',
GROUP_CONCAT(if(DAY(`Date`) = 14, `Status`, NULL)) AS 'day14',
GROUP_CONCAT(if(DAY(`Date`) = 15, `Status`, NULL)) AS 'day15',
GROUP_CONCAT(if(DAY(`Date`) = 16, `Status`, NULL)) AS 'day16',
GROUP_CONCAT(if(DAY(`Date`) = 17, `Status`, NULL)) AS 'day17',
GROUP_CONCAT(if(DAY(`Date`) = 18, `Status`, NULL)) AS 'day18',
GROUP_CONCAT(if(DAY(`Date`) = 19, `Status`, NULL)) AS 'day19',
GROUP_CONCAT(if(DAY(`Date`) = 20, `Status`, NULL)) AS 'day20',
GROUP_CONCAT(if(DAY(`Date`) = 21, `Status`, NULL)) AS 'day21',
GROUP_CONCAT(if(DAY(`Date`) = 22, `Status`, NULL)) AS 'day22',
GROUP_CONCAT(if(DAY(`Date`) = 23, `Status`, NULL)) AS 'day23',
GROUP_CONCAT(if(DAY(`Date`) = 24, `Status`, NULL)) AS 'day24',
GROUP_CONCAT(if(DAY(`Date`) = 25, `Status`, NULL)) AS 'day25',
GROUP_CONCAT(if(DAY(`Date`) = 26, `Status`, NULL)) AS 'day26',
GROUP_CONCAT(if(DAY(`Date`) = 27, `Status`, NULL)) AS 'day27',
GROUP_CONCAT(if(DAY(`Date`) = 28, `Status`, NULL)) AS 'day28',
GROUP_CONCAT(if(DAY(`Date`) = 29, `Status`, NULL)) AS 'day29',
GROUP_CONCAT(if(DAY(`Date`) = 30, `Status`, NULL)) AS 'day30',
GROUP_CONCAT(if(DAY(`Date`) = 31, `Status`, NULL)) AS 'day31',
COUNT(if(`Status`='Y', `Status`, NULL)) AS 'total' FROM `attendance`
WHERE `Date` BETWEEN '$f' AND '$t' GROUP BY Name_of_Student" ;
$classwise = mysql_query($query_classwise, $dbconnect) or die(mysql_error());
$row_classwise = mysql_fetch_assoc($classwise);
$totalRows_classwise = mysql_num_rows($classwise);
?>
我的查询很长,我不明白我的查询是否正确,我的php知识非常有限,我尝试使用以下php代码输出:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {color: #666600}
.style2 {color: #000000}
-->
</style>
</head>
<body>
<table width="640" border="0" align="center" cellpadding="4" cellspacing="4">
<tr>
<td width="48" bgcolor="#000000"><div align="center">SL No</div></td>
<td width="225" bgcolor="#000000"><div align="center">Name of Student</div></td>
<td width="45" bgcolor="#000000"><div align="center">Roll no</div></td>
<td width="45" bgcolor="#000000">Day 1 </td>
<td width="45" bgcolor="#000000">Day 2</td>
<td width="45" bgcolor="#000000">Day 3 </td>
</tr>
<?php do { ?>
<tr>
<td bgcolor="#333333"><div align="center"><?php echo $count++; ?></div></td>
<td bgcolor="#333333"><?php echo $row_classwise['Name_of_Student']; ?></td>
<td bgcolor="#333333"><div align="center"><?php echo $row_classwise['Roll_no'];
?> </div></td>
<td bgcolor="#333333"><?php echo $row_classwise['day1']; ?></td>
<td bgcolor="#333333"><?php echo $row_classwise['day2']; ?></td>
<td bgcolor="#333333"><?php echo $row_classwise['day3']; ?></td>
</tr>
<?php } while ($row_classwise = mysql_fetch_assoc($classwise)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($classwise);
?>
我想在每一天(第 1 天、第 2 天等)列下获得正确的 Y 或 N。到目前为止它没有输出所需的结果如果需要我可以提供表格...
这是我的新查询,我想将 -/- 和 - 放在星期六和星期日或假日的位置:
SELECT Students.Name_of_Student, Students.Roll_no, Students.Class, Students.Section, allDays.aDay,
GROUP_CONCAT(IFNULL(attendance.Status, '-') ORDER BY TimePeriod.`time` DESC SEPARATOR '/') AS Status
FROM (SELECT DISTINCT Name_of_Student, Roll_no, Class, Section FROM attendance ) AS Students
CROSS JOIN (SELECT 1 AS aDay UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION
SELECT 10 AS aDay UNION SELECT 11 UNION SELECT 12 UNION SELECT 13 UNION SELECT 14 UNION SELECT 15 UNION SELECT 16 UNION SELECT 17 UNION SELECT 18 UNION SELECT 19 UNION
SELECT 20 AS aDay UNION SELECT 21 UNION SELECT 22 UNION SELECT 23 UNION SELECT 24 UNION SELECT 25 UNION SELECT 26 UNION SELECT 27 UNION SELECT 28 UNION SELECT 29 UNION
SELECT 30 UNION SELECT 31) allDays
CROSS JOIN (SELECT 'Morning' AS `time` UNION SELECT 'Afternoon') TimePeriod
LEFT OUTER JOIN attendance ON Students.Name_of_Student = attendance.Name_of_Student AND allDays.aDay = DAY(`Date`)
AND BINARY TimePeriod.`time` = BINARY attendance.`time` where Date Between '$f' and '$t' and Students.Section='$s' and Students.Class='$c'
GROUP BY Students.Name_of_Student, Students.Roll_no, Students.Section, allDays.aDay
ORDER BY Students.Name_of_Student, allDays.aDay