2013-07-04 7 views
1
를 사용하여 datewise 출석을보기
<?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에서 내 지식은 매우 제한되어, 정확 여부 이해하지 못하고, 매우 긴 :는 phpmysql

<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); 
?> 

매일 (day1, day2 등) 열 아래에서 올바른 Y 또는 N을 가져 오려고합니다. 필요한 경우 지금까지 출력 원하는 resultI 여기

내 새 쿼리입니다 ... 테이블을 제공 할 수없는, 내가 데려 가고 싶다는 -/- 및 - 날이 토요일과 일요일이나 휴일입니다 :

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 
+0

쿼리의 상태가 1,0인지 또는 무엇입니까? – Naeem

+0

@ 노미 현재 'Y'와 부재중 'N'은 –

+1

입니다. http://stackoverflow.com/questions/17468945/attendance-view/17469153?noredirect=1#comment25385300_17469153 –

답변

3

전체 라인을 얻으 려하지 않고 매일 사람 당 행을 얻는 것이 더 쉬울 것입니다. 그런 다음 귀하의 PHP 코드에서 사람이 바뀔 때 새로운 라인을 던집니다. 이 같은

SQL 뭔가 : -

SELECT Students.Name_of_Student, Students.Roll_no, Students.Section, allDays.aDay, attendence.Status 
FROM (SELECT DISTINCT Name_of_Student FROM attendence WHERE `Date` BETWEEN '$f' AND '$t') 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 
LEFT OUTER JOIN attendence 
ON Students.Name_of_Student = attendence.Name_of_Student AND allDays.aDay = DAY(`Date`) 
WHERE `Date` BETWEEN '$f' AND '$t' 

이것은 해당 월의 모든 일의 목록 (당신이 학생 테이블이 있다면 쉬울 것) 학생들의리스트를 받고있다. 그런 다음 출석에 반대하는 사람들과 합류하십시오.

귀하의 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 
$PrevName_of_Student = ''; 
while ($row_classwise = mysql_fetch_assoc($classwise)) 
{ 
    if ($PrevName_of_Student != $row_classwise['Name_of_Student']) 
    { 
     if ($PrevName_of_Student ! = '') 
     { 
      echo '</tr>'; 
     } 
     ?><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> 
     <?php 
     $PrevName_of_Student = $row_classwise['Name_of_Student']; 
    } 
?> 
    <td bgcolor="#333333"><?php echo $row_classwise['Status']; ?></td> 
    </tr> 
<?php 
} 
if ($PrevName_of_Student ! = '') 
{ 
    echo '</tr>'; 
} 
?> 
</table> 
</body> 
</html> 
<?php 
mysql_free_result($classwise); 
?> 

이 함께이 같은 얻을 퍼팅 (테스트 및 작업)

<?php 

$link = mysql_connect('localhost', 'root', ''); 
If (!$link) 
{ 
    die ('Could not connect: ' . mysql_error()); 
} 
@mysql_select_db('testarea') or die ('Unable to select database'); 

$query = "SELECT Students.Name_of_Student, Students.Roll_no, Students.Section, allDays.aDay, attendance.Status, TimePeriod.`time` 
FROM (SELECT DISTINCT Name_of_Student, Roll_no, 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` 
ORDER BY Students.Name_of_Student, allDays.aDay, TimePeriod.`time` DESC"; 

$classwise = mysql_query($query); 

?> 
<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" ><div align="center">SL No</div></td> 
<td width="225" ><div align="center">Name of Student</div></td> 
<td width="45" ><div align="center">Roll no</div></td> 
<?php 
for($iCnt = 1; $iCnt <=31; $iCnt++) 
{ 
    foreach(array("Morning", "Afternoon") AS $TimePeriod) 
    { 
     echo "<td width='45' >Day $iCnt $TimePeriod</td>"; 
    } 
} 
echo "</tr>"; 
$PrevName_of_Student = ''; 
$count = 0; 
while ($row_classwise = mysql_fetch_assoc($classwise)) 
{ 
    if ($PrevName_of_Student != $row_classwise['Name_of_Student']) 
    { 
     if ($PrevName_of_Student != '') 
     { 
      echo '</tr>'; 
     } 
     echo "<tr>"; 
     echo "<td ><div align='center'>".$count++."</div></td>"; 
     echo "<td >".$row_classwise['Name_of_Student']."</td>"; 
     echo "<td ><div align='center'>".$row_classwise['Roll_no']."</div></td>"; 
     $PrevName_of_Student = $row_classwise['Name_of_Student']; 
    } 
    echo "<td >".$row_classwise['Status']."</td>"; 
} 
if ($PrevName_of_Student != '') 
{ 
    echo '</tr>'; 
} 
mysql_free_result($classwise); 
?> 
</table> 
</body> 
</html> 

EDIT 것 - 아침과 오후 병합 한 사람의 하루 기록 : -

<?php 

$link = mysql_connect('localhost', 'root', ''); 
If (!$link) 
{ 
    die ('Could not connect: ' . mysql_error()); 
} 
@mysql_select_db('testarea') or die ('Unable to select database'); 

$query = "SELECT Students.Name_of_Student, Students.Roll_no, 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, 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` 
GROUP BY Students.Name_of_Student, Students.Roll_no, Students.Section, allDays.aDay 
ORDER BY Students.Name_of_Student, allDays.aDay"; 

$classwise = mysql_query($query); 

?> 
<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" ><div align="center">SL No</div></td> 
<td width="225" ><div align="center">Name of Student</div></td> 
<td width="45" ><div align="center">Roll no</div></td> 
<?php 
for($iCnt = 1; $iCnt <=31; $iCnt++) 
{ 
    echo "<td width='45' >Day $iCnt </td>"; 
} 
echo "</tr>"; 
$PrevName_of_Student = ''; 
$count = 0; 
while ($row_classwise = mysql_fetch_assoc($classwise)) 
{ 
    if ($PrevName_of_Student != $row_classwise['Name_of_Student']) 
    { 
     if ($PrevName_of_Student != '') 
     { 
      echo '</tr>'; 
     } 
     echo "<tr>"; 
     echo "<td ><div align='center'>".$count++."</div></td>"; 
     echo "<td >".$row_classwise['Name_of_Student']."</td>"; 
     echo "<td ><div align='center'>".$row_classwise['Roll_no']."</div></td>"; 
     $PrevName_of_Student = $row_classwise['Name_of_Student']; 
    } 
    echo "<td >".$row_classwise['Status']."</td>"; 
} 
if ($PrevName_of_Student != '') 
{ 
    echo '</tr>'; 
} 
mysql_free_result($classwise); 
?> 
</table> 
</body> 
</html> 

EDIT - 업데이트 된 쿼리.

참고 학생 목록을 가져 오는 하위 선택 내에서 학생을 제한하기 위해 절을 넣었습니다. 또한 날짜에 대한 점검은 LEFT OUTER JOIN의 ON 절을 사용하여 실제 참석자를 얻습니다. 학생이 해당 기간에 수업에 출석하지 않은 경우에도 보고서에 계속 표시됩니다 (매일 -/- 함께).

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 where Section='$s' AND Class='$c') 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` 
AND Date Between '$f' and '$t' 
GROUP BY Students.Name_of_Student, Students.Roll_no, Students.Section, allDays.aDay 
ORDER BY Students.Name_of_Student, allDays.aDay 
+0

대단히 감사합니다. 내가 만들고 싶은 것은 다음과 같습니다. http://postimg.org/image/t46xc1laz/ 다시 한번 감사드립니다. –

+0

방금 ​​PHP 코드를 테스트 한 결과 아무 것도 출력되지 않습니다 .. –

+0

쿼리가 작동하지 않습니다 ... 'unknown column Students.Roll_no' –