|
|
|
ในฐานข้อมูล มีข้อมูลไม่ซ้ำกันแต่เวลา เอาออกมาแสดง กับมีข้อมูลขึ้นซ้อนกัน มีวิธีแก้ยังไงบ้างคับ ทำไม่ซักที |
|
|
|
|
|
|
|
ขึ้นแบบนี้มีโค้ดกับตัวอย่าง
Code (PHP)
<?
ob_start();
session_start();
if (isset($_SESSION["valid_uname"])){
include "s_menu.php";
include "phpconfig.php";
$sql = "SELECT*FROM student where s_username='$valid_uname'";
$result = mysql_query($sql,$conn);
$rs1= mysql_fetch_array($result);
$L_id = $rs1['L_id'];
$txtcate=$_POST['txtcate'];
if($txtcate==0){
$sql1 = "SELECT*FROM student n,
schedule s,
subject d,
year y,
teacher t,
level c
WHERE n.L_id=s.L_id
AND s.Sub_id=d.Sub_id
AND s.y_id=y.y_id
AND s.L_id=c.L_id
";
}
else{
$sql1 = "SELECT * FROM student n,
schedule s,
subject d,
year y,
teacher t,
level c
WHERE n.L_id=c.L_id
AND s.Sub_id=d.Sub_id
AND s.y_id=y.y_id
AND s.L_id=c.L_id
AND s.y_id='$txtcate'";
}
//echo "$sql1";
$result1 = mysql_query($sql1,$conn);
$rs2=mysql_fetch_array($result1);
?>
<!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" />
<title>Untitled Document</title>
</head>
<body>
<form action="s_subject.php" method="post" name="form1" id="form1" style="text-align: center">
<table width="1126" border="0">
<tr>
<td> </td>
</tr>
</table>
<p>เลือกปีการศึกษา :
<select name="txtcate" id="txtcate">
<option value="0">ทั้งหมด</option>
<?
$sql="select * from year";
$result=mysql_query($sql,$conn);
while($rs=mysql_fetch_array($result)){
echo"<option value=\"$rs[y_id]\">$rs[y_name]</option>\n";
}
?>
</select>
<input type="submit" name="button" id="button" value="ค้นหา" />
</p>
</form>
<p> </p>
<table width="200" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><span style="text-align: left"><span style="font-weight: bold">ค้นหาจาก</span>
<?
if($txtcate==""||$txtcate=="0"){
echo"ทั้งหมด";
}
else{
$sql="select * from year where y_id='$txtcate'";
$result=mysql_query($sql,$conn);
$rs=mysql_fetch_array($result);
echo"$rs[y_name]";
}
?>
</span></td>
</tr>
</table>
<form id="form2" name="form2" method="post" action="">
<p> </p>
<table width="1024" align="center">
<tr></tr>
<tr>
<th colspan="7"><div align="center"> <strong>ตารางเรียน</strong> <? echo"$rs2[L_name]";?></div></th>
</tr>
<tr>
<td width="100"> </td>
<td width="129"> </td>
<td width="145"> </td>
<td width="173"> </td>
<td width="149"> </td>
</tr>
<tr bgcolor="#0099FF">
<td width="100"align="center"bgcolor="#0099FF"><font face="MS Sans Serif, DB ThaiText" size="2">ปีการศึกษา</font></td>
<td width="129"align="center"bgcolor="#0099FF"><font face="MS Sans Serif, DB ThaiText" size="2">วิชา</font></td>
<td width="145"align="center"bgcolor="#0099FF"><font face="MS Sans Serif, DB ThaiText" size="2">ครูผู้สอน</font></td>
<td width="173"align="center"bgcolor="#0099FF"><font face="MS Sans Serif, DB ThaiText" size="2">เวลาเรียน</font></td>
<td width="149"align="center"bgcolor="#0099FF"><font face="MS Sans Serif, DB ThaiText" size="2">วันที่เรียน</font></td>
</tr>
<?
while($rs1=mysql_fetch_array($result1)){
$bgc=($bgc=="#fff0e1") ? "" : "#fff0e1";
?>
<tr>
<td align="center"bgcolor="<?=$bgc?>"><font face="MS Sans Serif, DB ThaiText" size="2"><? echo"$rs1[y_name]";?></font></td>
<td align="center"bgcolor="<?=$bgc?>"><font face="MS Sans Serif, DB ThaiText" size="2"><? echo"$rs1[Sub_name]";?></font></td>
<td align="center"bgcolor="<?=$bgc?>"><font face="MS Sans Serif, DB ThaiText" size="2"><? echo"$rs1[t_name]";?></font></td>
<td align="center"bgcolor="<?=$bgc?>"><font face="MS Sans Serif, DB ThaiText" size="2"><? echo"$rs1[sch_time]";?></font></td>
<td align="center"bgcolor="<?=$bgc?>"><font face="MS Sans Serif, DB ThaiText" size="2"><? echo"$rs1[sch_date]";?></font></td>
</tr>
<?
}
mysql_close($conn);
?>
</table>
<p align="center"> </p>
</form>
<?
}
else{
echo"<script>alert('คุณยังไม่ได้ล็อกอิน กรุณาล็อกอนก่อน'); window.location='index.php'; </script>";
exit();
}
?>
<p> </p>
</body>
</html>
Tag : PHP, MySQL
|
ประวัติการแก้ไข 2016-06-02 04:22:46
|
|
|
|
|
Date :
2016-06-02 04:21:29 |
By :
upvirus |
View :
709 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อาจจะต้องไปใช้ GROUP BY หรือ DISTINCT ครับ
|
|
|
|
|
Date :
2016-06-02 09:46:18 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|