|
|
|
สอบถามเรื่องการทำตารางสอน/เรียน ให้แสดงเฉพาะเวลาที่มีเรียน ไม่มีเรียนไม่ต้องแสดง |
|
|
|
|
|
|
|
จากที่ผมได้ศึกษาการทำตารางเรียน จึงได้ออกมาเป็นแบบนี้
คือผมอยากจะให้เวลาที่ว่างนั้น ไม่ต้องแสดง ให้แสดงแต่เวลาที่มีเรียน ผมควรจะทำยังไงดีครับ
Code (PHP)
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.tree {
font-family: Arial, Helvetica, sans-serif; font-size: 9;
border: 1px solid black;
}
.tree th {
border: 1px solid #FFFFFF;
}
.tree td {
border: 1px solid #FFFFFF;
}
.no{ width : 100px; text-align : center;}
.highlight{ background-color : #ffccaa; }
.style2 {
color: #FFFFFF;
font-size: 11px;
}
.style3 {color: #FFFF33; font-size: 11px;}
.style5 {color: #FF99CC}
.style7 {color: #00FF33}
.style9 {color: #FF9933}
.style10 {color: #00FFCC}
.style11 {color: #FFFFCC}
.style13 {color: #999933}
-->
.no{ width : 100px; text-align : center;}
.highlight{ background-color : #99aaff; font-size: 11px; }
.title{ text-align : center;}
</style>
</head>
<body >
<div class="container">
<div class="row">
<form name="form1" method="post" action="taraStd.php">
<table class="table table-striped" border="0" >
<tr>
<td colspan="4" >
<a style="bottom:left;" href="taraStd.php" type="button" class="btn btn-info"><span class="glyphicon glyphicon-refresh"></span> Refresh Data</a>
</td>
<td colspan="4" align="right">
ค้นหาจากรหัสนักเรียน :
<input type="text" align="right" placeholder="ค้นหาตารางเรียนนักเรียน" value="<?=$_POST["txtKeyword"];?>" name="txtKeyword"/>
<input type="submit" name="submit" value="ค้นหา">
</td>
</tr>
</table>
<div class="table-responsive">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tree" align="center" >
<tr>
<td width="7%" valign="top">
<table width="100%" border="1" cellspacing="0" cellpadding="0" bordercolor="#FFFFFF" >
<tr>
<td height="34" align="center" bgcolor="#333333" style=""><span class="style2"><font color="#FFFFFF">วัน/เวลา</font></span></td>
</tr>
<?
$sql5="select * from tb_day";
$query5=mysql_query($sql5);
while($objResult = mysql_fetch_array($query5)){
?>
<tr>
<td height="39" align="center" bgcolor="#999999"><span class="style3"><font color="#FFFFFF"><?php echo $objResult["Name_day"];?></font></span></td>
</tr>
<?
}
?>
</table>
</td>
<td align="left" valign="top" bgcolor="#FFFFFF" >
<?php
$sql="select * from register";
$query=mysql_query($sql);
$timeArr = array(
0 => array( "start" => "09.00", "stop" => "10.00"),
1 => array( "start" => "10.00", "stop" => "11.00"),
2 => array( "start" => "11.00", "stop" => "12.00"),
3 => array( "start" => "12.00", "stop" => "13.00"),
4 => array( "start" => "13.00", "stop" => "14.00"),
5 => array( "start" => "14.00", "stop" => "15.00"),
6 => array( "start" => "15.00", "stop" => "16.00"),
7 => array( "start" => "16.00", "stop" => "17.00"),
8 => array( "start" => "17.00", "stop" => "18.00"),
9 => array( "start" => "18.00", "stop" => "19.00"),
10 => array( "start" => "19.00", "stop" => "20.00"),
11 => array( "start" => "20.00", "stop" => "21.00"),
);
?>
<?php
/* Key Positon */
function getCol($haystack, $keyNeedle)
{
$i = 0;
foreach($haystack as $arr)
{
if($arr['start'] == $keyNeedle)
{
return $i;
}
$i++;
}
}
/* Time Range */
function getTimeRange($timeT, $timeCol){
$data = array();
foreach($timeT as $timeA){
$time = $timeA['time'];
if(!$time) continue;
$tm = explode("-", $time);
//echo '<pre>', print_r($tm,true) ,'</pre>';
$start = getCol($timeCol, $tm[0]);
$end = getCol($timeCol, $tm[1] );
$colspan = $end - $start;
$data[$tm[0]] = array('colspan' => $colspan, 'title' => $timeA['title']);
}
return $data;
}
?>
<?php
$timeTeach = array(
0 => array(),
1 => array(),
2 => array(),
3 => array(),
4 => array(),
5 => array(),
6 => array()
);
if ($_POST["txtKeyword"] == ""){
$date = date("Y-m-d");
for($i=0;$i<7;$i++){
$strSQL = "SELECT * FROM tb_register WHERE status = 0 " ;
$query = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($result=mysql_fetch_array($query)){
}
}
}else{
for($i=0;$i<7;$i++){
$strSQL = "SELECT * FROM tb_detailregis WHERE 1 " ;
if($_POST["txtKeyword"] != ''){
$strSQL .= " AND (ID_student LIKE '".$_POST["txtKeyword"]."' ) ";
}
$query = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($result=mysql_fetch_array($query)){
$fetc_pro = mysql_fetch_array(mysql_query("SELECT * FROM tb_register WHERE ID_regis=".$result['ID_register'].""));
$Result_tp = mysql_fetch_array(mysql_query("SELECT * FROM tb_typecourse WHERE ID_typeCourse='$fetc_pro[ID_typeCourse]'"));
$tid=$fetc_pro["ID_day"];
$timeTeach[$tid][] = array('time' => $fetc_pro["start_time"].'-'.$fetc_pro["end_time"], 'title' => '<a href="showregisStd.php?showregisStd_id='.$fetc_pro["ID_regis"].'">'.$fetc_pro["ID_regis"].'</a>'." ".$Result_tp["type_name"]);
}
}
}
?>
<?php
$list = "";
echo '<table border="1" bordercolor="#FFFFFF" width="100%" align="center" cellspacing="0">';
echo '<tr>';
echo '<td width="8.3%" height="34" colspan="1" align="center" bgcolor="#333333"><font color="#FFFFFF"><span class="style2">9:00-10:00</span></td>';
echo '<td width="8.3%" colspan="1" align="center" bgcolor="#333333"><font color="#FFFFFF"><span class="style2">10:00-11:00</span></td>';
echo '<td width="8.3%" colspan="1" align="center" bgcolor="#333333"><font color="#FFFFFF"><span class="style2">11:00-12:00</span></td>';
echo '<td width="8.3%" colspan="1" align="center" bgcolor="#333333"><font color="#FFFFFF"><span class="style2">12:00-13:00</span></td>';
echo '<td width="8.3%" colspan="1" align="center" bgcolor="#333333"><font color="#FFFFFF"><span class="style2">13:00-14:00</span></td>';
echo '<td width="8.3%" colspan="1" align="center" bgcolor="#333333"><font color="#FFFFFF"><span class="style2">14:00-15:00</span></td>';
echo '<td width="8.3%" colspan="1" align="center" bgcolor="#333333"><font color="#FFFFFF"><span class="style2">15:00-16:00</span></td>';
echo '<td width="8.3%" colspan="1" align="center" bgcolor="#333333"><font color="#FFFFFF"><span class="style2">16:00-17:00</span></td>';
echo '<td width="8.3%" colspan="1" align="center" bgcolor="#333333"><font color="#FFFFFF"><span class="style2">17:00-18:00</span></td>';
echo '<td width="8.3%" colspan="1" align="center" bgcolor="#333333"><font color="#FFFFFF"><span class="style2">18:00-19:00</span></td>';
echo '<td width="8.3%" colspan="1" align="center" bgcolor="#333333"><font color="#FFFFFF"><span class="style2">19:00-20:00</span></td>';
echo '<td width="8.3%" colspan="1" align="center" bgcolor="#333333"><font color="#FFFFFF"><span class="style2">20:00-21:00</span></td>';
echo '</tr>';
foreach($timeTeach as $i=>$arr){
$timeT = $timeTeach[$i];
$arrRange = getTimeRange($timeT, $timeArr);
$list = '<tr bgcolor="#E8E8E8">';
$chkCol = 0;
$col = 0;
foreach( $timeArr as $timeA ){
$highlight = "";
$colspan = "";
if($chkCol < ($col-1) && $col != 0){
$chkCol++;
continue;
}
$title = " ";
$col = 0;
$chkCol = 0;
if(!empty($arrRange[trim($timeA['start'])])){
$col = $arrRange[trim($timeA['start'])]['colspan'];
$title = $arrRange[trim($timeA['start'])]['title'];
$highlight = "highlight";
$colspan = 'colspan="'.$col.'"';
}
$list .= '<td '.$colspan.' class="'. $highlight .' title" height="39" align="center">' . $title . '</td>';
}
$list .= '</tr>';
echo $list;
}
echo '</table>';
?>
</td>
</tr>
</table>
</table>
</div>
</form>
</div>
Tag : PHP, MySQL, HTML/CSS, jQuery
|
|
|
|
|
|
Date :
2016-02-20 23:58:18 |
By :
อยากรู้ |
View :
3272 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองดูพวกเงื่อนไขที่เป็น else ของ if(!empty($arrRange[trim($timeA['start'])])){
|
|
|
|
|
Date :
2016-02-21 22:46:14 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|