|
|
|
Select Mysql ข้อมูลออกซ้ำค่ะ เป็นแค่บางแถว รบกวนช่วยแนะนำด้วยค่ะ |
|
|
|
|
|
|
|
นี่คือโค้ดค่ะ รบกวนช่วยหน่อยค่ะ ทำไมถึงวนซ้ำเฉพาะแค่บางแถว <span class="style10" style="background: #999999"> <-- อันนี้จะเปนแถวที่เปนสีเทาค่ะ
Code (PHP)
<?
include("dbconnect.php");
$id=$_SESSION['id'];
$year = $_GET["year"];
$term=$_GET["term"];
echo '<table width="787" border="1" cellpadding="1" cellspacing="0" bordercolor="#000000">';
echo '<tr>
<td width="45" rowspan="2" align="center" valign="middle" class="style10">วัน</td>
<td width="20" rowspan="2" align="center" valign="middle" class="style10">วันที่</td>
<td width="154" rowspan="2" align="center" valign="middle" class="style10">วิชา</td>
<td colspan="2" align="center" valign="middle" class="style10">เวลาที่สอนในเวลาราชการ</td>
<td width="20" rowspan="2" align="center" valign="middle" class="style10">ปวส.</td>
<td width="20" rowspan="2" align="center" valign="middle" class="style10">ป.ตรี</td>
<td width="40" rowspan="2" align="center" valign="middle" class="style10">ห้อง</td>
<td colspan="2" align="center" valign="middle" class="style10">เวลาที่สอนนอกเวลาราชการ</td>
<td width="20" rowspan="2" align="center" valign="middle" class="style10">ปวส.</td>
<td width="20" rowspan="2" align="center" valign="middle" class="style10">ป.ตรี</td>
<td width="40" rowspan="2" align="center" valign="middle" class="style10">ห้อง</td>
<td width="70" rowspan="2" align="center" valign="middle" class="style10">หมายเหตุ</td>
</tr>
<tr>
<td width="70" align="center" valign="middle" class="style10">ภาคทฤษฎี</td>
<td width="70" align="center" valign="middle" class="style10">ภาคปฏิบัติ</td>
<td width="70" align="center" valign="middle" class="style10">ภาคทฤษฎี</td>
<td width="70" align="center" valign="middle" class="style10">ภาคปฏิบัติ</td>
</tr>';
$sql="SELECT gendata_normal.per_id, gendata_normal.weekday, gendata_normal.date, gendata_normal.sub_name, gendata_normal.timestart, gendata_normal.timeend, gendata_normal.unit_time, gendata_normal.stu_name, gendata_normal.year, gendata_normal.term
FROM gendata_normal
INNER JOIN weekday ON gendata_normal.weekday= weekday.weekday where gendata_normal.year =".$year." and gendata_normal.term =".$term." and gendata_normal.per_id =".$id." ORDER BY gendata_normal.date";
$j=0;
$sum=0;
mysql_query("SET NAMES TIS620");
$query= mysql_query($sql) or die ("query error1");
$numrows=mysql_num_rows($query);//ให้นับจำนวนแถวทั้งหมด
while($row = mysql_fetch_array($query))
{
$per_id=$row['per_id'];
$weekday=$row['weekday'];
$date=$row['date'];
$sub_name=$row['sub_name'];
$timestart=$row['timestart'];
$timeend=$row['timeend'];
$unit_time=$row['unit_time'];
$stu_name=$row['stu_name'];
$year=$row['year'];
$term=$row['term'];
$Amonth = split("-",$date);
$monthPayment = $Amonth[1];
$Adate = split("-",$date);
$datePayment = $Adate[2];
$sql_holiday="SELECT gendata_normal.date, holiday.holiday, holiday.date, holiday.normal
FROM gendata_normal
INNER JOIN holiday ON ( gendata_normal.date = holiday.date )
WHERE gendata_normal.date = holiday.date and gendata_normal.per_id =".$id;
mysql_query("SET NAMES TIS620");
$query_holiday= mysql_query($sql_holiday) or die ("query error2");
$numrows_holiday=mysql_num_rows($query_holiday);
while($row = mysql_fetch_array($query_holiday))
{
$holiday=$row['holiday'];
$holidaydate=$row['date'];
$normal=$row['normal'];
if($normal==1 and $date==$holidaydate)
{
echo ' <tr>';
echo '
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999">'.acronym($monthPayment)."- ".thaiweek($weekday).'</span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999">'.$datePayment.'</span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999">'.$sub_name.'</span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999">'.$timestart."-".$timeend.'</span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999"></span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999"></span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999">'.$unit_time.'</span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999">'.$stu_name.'</span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999"></span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999"></span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999"></span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999"></span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999"></span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999">'.$holiday.'</span></td>';
}
}
$sql_academic="SELECT gendata_normal.date, gendata_normal.timestart, gendata_normal.timeend, academiccalen_normal.academic_list, academiccalen_normal.semester
FROM gendata_normal
INNER JOIN academiccalen_normal ON ( gendata_normal.date = academiccalen_normal.semester )
WHERE gendata_normal.date = academiccalen_normal.semester
AND gendata_normal.per_id =".$id;
mysql_query("SET NAMES TIS620");
$query_academic= mysql_query($sql_academic) or die ("query error3");
$numrows_academic=mysql_num_rows($query_academic);
while($row = mysql_fetch_array($query_academic))
{
$academic_list=$row['academic_list'];
$academicdate=$row['date'];
if($date==$academicdate)
{
echo ' <tr>';
echo '
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999">'.acronym($monthPayment)."- ".thaiweek($weekday).'</span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999">'.$datePayment.'</span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999">'.$sub_name.'</span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999">'.$timestart."-".$timeend.'</span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999"></span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999"></span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999">'.$unit_time.'</span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999">'.$stu_name.'</span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999"></span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999"></span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999"></span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999"></span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999"></span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999">'.$academic_list.'</span></td>';
}
}
$sql_changeteach="SELECT changeteach.change_date, changeteach.new_date, changeteach.timetable_id, changeteach.newtime_start, timetable.per_id, changeteach.newtime_end, changeteach.reason, changeteach.status, subject.sub_id, student_class.stu_id
FROM changeteach
INNER JOIN timetable ON ( changeteach.timetable_id = timetable.timetable_id )
INNER JOIN subject ON ( timetable.sub_id = subject.sub_id )
INNER JOIN student_class ON ( timetable.stu_id = student_class.stu_id )
WHERE changeteach.status =4
AND timetable.per_id =".$id;
mysql_query("SET NAMES TIS620");
$query_changeteach= mysql_query($sql_changeteach) or die ("query error3");
$numrows_changeteach=mysql_num_rows($query_changeteach);
while($row = mysql_fetch_array($query_changeteach))
{
$reason=$row['reason'];
$changeteachdate=$row['change_date'];
if($date==$changeteachdate)
{
echo ' <tr>';
echo '
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999">'.acronym($monthPayment)."- ".thaiweek($weekday).'</span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999">'.$datePayment.'</span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999">'.$sub_name.'</span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999">'.$timestart."-".$timeend.'</span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999"></span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999"></span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999">'.$unit_time.'</span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999">'.$stu_name.'</span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999"></span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999"></span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999"></span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999"></span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999"></span></td>
<td class="style7" bgcolor="#999999"><span class="style10" style="background: #999999">'.$reason.'</span></td>';
}
}
if ($date!=$holidaydate and $date!=$academicdate)
{
echo ' <tr>';
echo '
<td class="style7"><span class="style10">'.acronym($monthPayment)."- ".thaiweek($weekday).'</span></td>
<td class="style7"><span class="style10">'.$datePayment.'</span></td>
<td class="style7"><span class="style10">'.$sub_name.'</span></td>
<td class="style7"><span class="style10">'.$timestart."-".$timeend.'</span></td>
<td class="style10"></td>
<td class="style10"></td>
<td class="style7"><span class="style10">'.$unit_time.'</span></td>
<td class="style7"><span class="style10">'.$stu_name.'</span></td>
<td class="style10"></td>
<td class="style10"></td>
<td class="style10"></td>
<td class="style10"></td>
<td class="style10"></td>
<td class="style10"></td>';
$sum=$sum+$unit_time;
}
$j++;
}
?>
<?
$sql="SELECT personnel.per_id, position_manage.load_mana AS m_load, position_technical.load_tech AS t_load FROM personnel
inner join position_manage on (personnel.position_idmana = position_manage.position_idmana)
inner join position_technical on (personnel.position_idtec = position_technical.position_idtec)
where personnel.per_id =".$id;
mysql_query("SET NAMES TIS620");
$query= mysql_query($sql) or die ("query error4");
$numrows=mysql_num_rows($query);
for($i=1;$i<=$numrows;$i++){
$data=mysql_fetch_array($query);
$m_load = $data["m_load"];
$t_load = $data["t_load"];
?>
<?
if($m_load!=0)
{
$load=$m_load;
}
else
{
$load=$t_load;
}
?>
<? } ?>
<?
$sql="SELECT *
FROM `load`
WHERE `load` =".$load;
mysql_query("SET NAMES TIS620");
$query= mysql_query($sql) or die ("query error5");
$numrows=mysql_num_rows($query);
for($i=1;$i<=$numrows;$i++){
$data=mysql_fetch_array($query);
$load = $data["load"];
$teachnot_credit = $data["teachnot_credit"];
$widennot_credit = $data["widennot_credit"];
$not_baht = $data["not_baht"];
}
?>
<?
echo '
</tr>
<tr>
<td colspan="5" align="center" class="style7"> <span class="style10"><strong>รวมเวลาที่สอน</strong></span></td>
<td class="style10"></td>
<td class="style10">'.$sum.'</td>
<td class="style10"></td>
<td class="style10"></td>
<td class="style10"></td>
<td class="style10"></td>
<td class="style10"></td>
<td class="style10"></td>
<td class="style10"></td>
</tr>
</table>';
?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2013-03-05 11:53:51 |
By :
มะเหมี่ยว |
View :
805 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วค่ะ ขอบคุณ คุณ gap มากน๊ะค๊ะ
เพิ่มเงื่อนไข
Code (PHP)
$sql_holiday="SELECT gendata_normal.date, holiday.holiday, holiday.date, holiday.normal, gendata_normal.timestart, gendata_normal.timeend
FROM gendata_normal
INNER JOIN holiday ON ( gendata_normal.date = holiday.date )
WHERE gendata_normal.date = '".$date."' and gendata_normal.timestart = '".$timestart."' and gendata_normal.timeend= '".$timeend."' and gendata_normal.per_id =".$id;
เข้าไปค่ะ ขอบคุณค๊าาาาาาาาาา า า าา าาาา
|
|
|
|
|
Date :
2013-03-05 13:52:38 |
By :
มะเหมี่ยว |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|