|
|
|
โค้ดเกี่ยวกับการแสดงข้อมูลให้ตรงกับวันที่เลือกครับ |
|
|
|
|
|
|
|
ตอนนี้ผมทำมา 2 เพจครับ
1.index.php
2.calendar.php
index.php ไว้แสดงข้อมูล
calendar.php ทำปฏิทินไว้ให้เลือกวัน เพื่อแสดงข้อมูลตามวันนั้นๆ
ผมได้โค้ด calendar.php มาจากที่อื่นครับ แล้วผมเอามาปรับใช้ไม่เป็นครับอยากทราบว่าต้องทำยังไงครับ
********************** ถ้าใครว่างช่วยผมที่น่ะครับ (ถ้าไม่ว่างก้อช่วยดูให้ด้วยครับ)************************
เพจ index.php
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=windows-874" />
<title> </title>
<style type="text/css">
<!--
body {
background-image: url(bg/bg_nofade.jpg);
background-repeat: repeat;
}
-->
</style>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</head>
<body>
<?
function thaidate($s){
$months = array(1=>'มกราคม','กุมภาพันธ์','มีนาคม',
'เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม',
'กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม');
$t = strtotime($s);
$w_name=array ("อาทิตย์","จันทร์","อังคาร","พุธ","พฤหัสบดี","ศุกร์","เสาร์");
$w=date("w",$t);
$d=date('d',$t);
if ($d<10){
$d=substr($d,1,2);
}
return 'วัน'.$w_name[$w].' '.date($d,$t).' '.$months[date('n',$t)].' พ.ศ. '.(date('Y',$t)+543);
}
include "conn.inc.php";
$muang="ศาลหลักเมือง";
$maemo="สำนักงานการประปาแม่เมาะ";
$soppad="สถานอนามัยบ้านสบป้าด อ.แม่เมาะ";
$tahsee="สถานีอนามัยบ้านท่าสี";
$sql="SELECT * FROM tb_warn_air ORDER BY date_warn_air ASC";
$query=mysql_query($sql);
While($rs = mysql_fetch_array($query)){
$date_air = $rs["date_warn_air"];
$muang_aqi = $rs['muang_aqi'];
$maemo_aqi = $rs['maemo_aqi'];
$soppad_aqi = $rs['soppad_aqi'];
$tahsee_aqi = $rs['tahsee_aqi'];
$muang_pm10 = $rs['muang_pm10'];
$maemo_pm10 = $rs['maemo_pm10'];
$soppad_pm10 = $rs['soppad_pm10'];
$tahsee_pm10 = $rs['tahsee_pm10'];
$acts[$date_air] = empty($acts[$date_air]) ? $name : $acts[$date_air].', '.$name;
}
print $date_air.'<BR>'.$date[$date_air];
//------------------------------ AQi Start--------------------------------- //
if ($muang_aqi > $maemo_aqi){
$max_aqi=$muang_aqi;
$show_aqi=$muang;
}else{
$max_aqi=$maemo_aqi;
$show_aqi=$maemo;
}
if ($max_aqi < $soppad_aqi){
$max_aqi=$soppad_aqi;
$show_aqi=$soppad;
}
if ($max_aqi < $tahsee_aqi){
$max_aqi=$tahsee_aqi;
$show_aqi=$tahsee;
}
print "<BR>".$max_aqi."<BR>".$show_aqi;
//------------------------------ AQi End--------------------------------- //
//------------------------------ PM10 Start--------------------------------- //
if ($muang_pm10 > $maemo_pm10){
$max_pm10=$muang_pm10;
$show_pm10=$muang;
}else{
$max_pm10=$maemo_pm10;
$show_pm10=$maemo;
}
if ($max_pm10 < $soppad_pm10){
$max_pm10=$soppad_pm10;
$show_pm10=$soppad;
}
if ($max_pm10 < $tahsee_pm10){
$max_pm10=$tahsee_pm10;
$show_pm10=$tahsee;
}
print "<BR><BR>".$max_pm10."<BR>".$show_pm10;
//------------------------------ PM10 End--------------------------------- //
$maxdegree=270;
$lowdegree=1;
//---------------------------------- Start scale AQI --------------------------//
$ndegree=($maxdegree*$max_aqi);
$degree_aqi=$ndegree/400;
$true_aqi=round($degree_aqi);
//---------------------------------- End scale AQI --------------------------//
//---------------------------------- Start scale PM10 --------------------------//
$ndegree=($maxdegree*$max_pm10);
$degree_pm10=$ndegree/200;
$true_pm10=round($degree_pm10);
//---------------------------------- End scale PM10 --------------------------//
//----------------------------- คำนวณหาค่าสี ------------------------------//
if ($max_aqi>300){
$path_aqi="red";
}else if($max_aqi>200){
$path_aqi="orange";
}else if($max_aqi>100){
$path_aqi="yellow";
}else {
$path_aqi="green";
}
echo $path_aqi;
if($max_pm10>120){
$path_pm10="red";
}else{
$path_pm10="green";
}
//----------------------------- คำนวณหาค่าสี ------------------------------//
echo '<BR>'.$path_pm10;
/*$IMG_URL_aqi = "digit/".$path_aqi."/";
if ($max_aqi<100){
$NB_DIGITS_aqi = 2;
}else{
$NB_DIGITS_aqi = 3;
}
$count_aqi=$max_aqi;
chop($count_aqi);
if (!$num_row){
$count_aqi =0;
}
$nb_digits_aqi = max(strlen($count_aqi), $NB_DIGITS_aqi);
$count_aqi = substr("0000000000".$count_aqi, -$nb_digits_aqi);
$digits_aqi = preg_split("//", $count_aqi);
for($i = 0; $i <= $nb_digits_aqi; $i++) {
if ($digits_aqi[$i] != "") {
$print_aqi .= "<IMG SRC=\"$IMG_URL_aqi$digits_aqi[$i].gif\">";
}
}*/
//------------------------------ digit aqi ---------------------------------//
$IMG_URL_aqi = "digit/".$path_aqi."/";
if ($max_aqi<100){
$NB_DIGITS_aqi = 2;
}else{
$NB_DIGITS_aqi = 3;
}
$count_aqi=$max_aqi;
//$count=$t;
chop($count_aqi);
$nb_digits_aqi = max(strlen($count_aqi), $NB_DIGITS_aqi);
$count_aqi = substr("0000000".$count_aqi, -$nb_digits_aqi);
$digits_aqi = preg_split("//", $count_aqi);
for($i = 0; $i <= $nb_digits_aqi; $i++) {
if ($digits_aqi[$i] != "") {
$print_aqi .= "<IMG SRC=\"$IMG_URL_aqi$digits_aqi[$i].gif\">";
}
}
//------------------------------ digit aqi ---------------------------------//
//------------------------------ digit aqi ---------------------------------//
$IMG_URL_pm10 = "digit/".$path_pm10."/";
if ($max_pm10<100){
$NB_DIGITS_pm10 = 2;
}else{
$NB_DIGITS_pm10 = 3;
}
$count_pm10=$max_pm10;
//$count=$t;
chop($count_pm10);
$nb_digits_pm10 = max(strlen($count_pm10), $NB_DIGITS_pm10);
$count_pm10 = substr("0000000".$count_pm10, -$nb_digits_pm10);
$digits_pm10 = preg_split("//", $count_pm10);
for($i = 0; $i <= $nb_digits_pm10; $i++) {
if ($digits_pm10[$i] != "") {
$print_pm10 .= "<IMG SRC=\"$IMG_URL_pm10$digits_pm10[$i].gif\">";
}
}
//------------------------------ digit aqi ---------------------------------//
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td background="bg/bg_footer.gif"> </td>
</tr>
<tr>
<td height="30" align="center" valign="bottom"> </td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="30%" align="center" valign="top"> </td>
<td width="35%" align="center" valign="middle"> </td>
<td width="35%"> </td>
</tr>
<tr>
<td colspan="3" align="center" valign="top">ข้อมูล ณ <?print thaidate($date_air);?> </td>
</tr>
<tr>
<td width="30%" align="center" valign="middle">ค่าสูงสุด AQI<BR>ณ
<?=$show_aqi;?></td>
<td width="35%"> </td>
<td width="35%"> </td>
</tr>
<tr>
<td width="30%" height="270" align="center" valign="top"><table width="270" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="270" align="center" valign="middle" background="bg/bg_cockpit.gif"><table width="260" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="227" align="center" valign="top" background="bg/bg_aqi01.jpg"><script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','260','height','228','src','swf_scale/<?=$true_aqi;?>','loop','false','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','wmode','transparent','movie','swf_scale/<?=$true_aqi;?>' ); //end AC code
</script>
<noscript>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="260" height="228">
<param name="movie" value="swf_scale/<?=$true_aqi;?>.swf" />
<param name="quality" value="high" />
<param name="wmode" value="transparent" />
<param name="LOOP" value="false" />
<embed src="swf_scale/<?=$true_aqi;?>.swf" width="260" height="228" loop="False" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" wmode="transparent"></embed>
</object>
</noscript> </td>
</tr>
<tr>
<td align="center" valign="top"><?=$print_aqi;?></td>
</tr>
</table></td>
</tr>
</table></td>
<td width="35%" rowspan="4"><img src="img/lpmap3.gif" width="400" height="500" /></td>
<td width="35%" rowspan="4"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td>
<?
print "1. ".$muang."<BR>AQI = ".$muang_aqi."<BR>PM10 = ".$muang_pm10."<BR><BR><BR>";
print "2. ".$maemo."<BR>AQI = ".$maemo_aqi."<BR>PM10 = ".$maemo_pm10."<BR><BR><BR>";
print "3. ".$soppad."<BR>AQI = ".$soppad_aqi."<BR>PM10 = ".$soppad_pm10."<BR><BR><BR>";
print "4. ".$tahsee."<BR>AQI = ".$tahsee_aqi."<BR>PM10 = ".$tahsee_pm10."<BR><BR><BR>";
?></td>
</tr>
</table></td>
</tr>
<tr>
<td width="30%" align="center" valign="top"> </td>
</tr>
<tr>
<td width="30%" align="center" valign="middle">ค่าสูงสุด PM10<BR>ณ
<?=$show_pm10;?></td>
</tr>
<tr>
<td width="30%" height="270" align="center" valign="top"><table width="270" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="270" align="center" valign="middle" background="bg/bg_cockpit.gif"><table width="260" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="227" align="center" valign="top" background="bg/bg_pm10_101.jpg"><script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','260','height','228','src','swf_scale/<?=$true_pm10;?>','loop','false','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','wmode','transparent','movie','swf_scale/<?=$true_pm10;?>' ); //end AC code
</script>
<noscript>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="260" height="228">
<param name="movie" value="swf_scale/<?=$true_pm10;?>.swf" />
<param name="quality" value="high" />
<param name="wmode" value="transparent" />
<param name="LOOP" value="false" />
<embed src="swf_scale/<?=$true_pm10;?>.swf" width="260" height="228" loop="False" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" wmode="transparent"></embed>
</object>
</noscript> </td>
</tr>
<tr>
<td align="center" valign="top"><?=$print_pm10;?></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>
<?include 'calendar.php';?> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td align="center" valign="top"><?include "content.html";?></td>
</tr>
<tr>
<td align="center" valign="top"> </td>
</tr>
</table>
</body>
<?mysql_close($Connect);?>
</html>
เพจ calendar.php
Code (PHP)
<?
$S=$_GET['S']; $Sday=$_GET['Sday']; $Smonth=$_GET['Smonth'];
$Syear=$_GET['Syear'];
if($Syear != "" and $Smonth != "" and $Sday != "")
{
$newday=$Sday;
$newday1 =$newday;
$newmonth=$Smonth;
$newmonth1=$Smonth;
if ($Sday < "10"){$newday1 ="0".$newday;}
if (strlen($Smonth) == "1" ){$newmonth1 ="0".$Smonth;}
$nowdate=$Syear.'-'.$newmonth1.'-'.$newday1;
// echo $nowdate;
}
if($_GET['Nmonth']!= "" and $_GET['Nyear'] != "")
{
$month = $_GET['Nmonth'];
$year=$_GET['Nyear'];
$newday1=date('d');
$nowdate=$year.'-'.$month.'-'.$newday1;
// echo $nowdate;
}
else if(!$S)
{
$month = date('m');
$year = date('Y');
}
else // ถ้าเลือกวัน
{
$month = $_GET['Smonth'];
$year=$_GET['Syear'];
}
if($month == 1)
{
$m_back = 12;
$m_next = $month + 1;
$y_back = $year -1;
$y_next = $year;
}
else if ($month == 12)
{
$m_back = $month - 1;
$m_next = 1;
$y_back = $year;
$y_next = $year + 1;
}
else
{
$m_back = $month - 1;
$m_next = $month + 1;
$y_back = $year;
$y_next = $year;
}
$mkdate = mktime(0,0,0,$month,1,$year);
$full_month = date('F',$mkdate);
$weekday=date('w',$mkdate);
$last_days=date('t',$mkdate);
$Tyear=date('Y',$mkdate)+543;
$ThMonth = array ( "มกราคม","กุมภาพันธ์","มีนานคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
$Tmonth=$ThMonth[date('m',$mkdate)-1];
$day=1;
$event=array(5,10,18,23);
$event_day=15;
?>
<style>
.menu_calender{background-color: #F5EAFF; } /* เปลี่ยนสีพื้นหลัง */
.menu_calender-over{background-color: #EBD7FF;} /* เปลี่ยนสีพื้นหลัง */
.style1 {font-family: Arial, Helvetica, sans-serif}
</style>
<center>เลือกดูข้อมูลตามวันที่</center>
<table width="20%" align="center" cellpadding="3" cellspacing="1" style="border:1px solid #FF6666; padding:2px;">
<tr style=" background-color: #C7FAE6;">
<!-- <td align="left" valign="middle"><a href="?Nmonth=<? echo"$m_back";?>&Nyear=<? echo"$y_back";?>&<? echo"S=$S&Sday=$Sday&Smonth=$Smonth&Syear=$Syear"?>"><img src="image/rewind.gif" border="0" /></a></td> -->
<td align="left" valign="middle"><a href="?Nmonth=<? echo"$m_back";?>&Nyear=<? echo"$y_back";?>&<? echo"S=$S&Sday=$Sday&Smonth=$Smonth&Syear=$Syear"?>"><</a></td>
<td colspan="5" align="center" valign="middle"><center><? echo "$Tmonth $Tyear";?>
</center></td>
<!-- <td align="right" valign="middle"><a href="?Nmonth=<? echo"$m_next";?>&Nyear=<? echo"$y_next";?>&<? echo"S=$S&Sday=$Sday&Smonth=$Smonth&Syear=$Syear";?>"><img src="image/forward.gif" border="0" /></a></td> -->
<td align="right" valign="middle"><a href="?Nmonth=<? echo"$m_next";?>&Nyear=<? echo"$y_next";?>&<? echo"S=$S&Sday=$Sday&Smonth=$Smonth&Syear=$Syear";?>">></a></td>
</tr>
<tr>
<td align="center" valign="middle">อา</td>
<td align="center" valign="middle">จ</td>
<td align="center" valign="middle">อ</td>
<td align="center" valign="middle">พ</td>
<td align="center" valign="middle">พฤ</td>
<td align="center" valign="middle">ศ</td>
<td align="center" valign="middle">ส</td>
</tr>
<tr>
<!-- //======================= part 3 ============================-->
<?
$start=1;
while ($start<=$weekday)
{
echo "<td> </td>";
$start++;
}
$weekday++;
while($day <= $last_days)
{
if(date('d')==$day && date('m')==$month && date('Y')==$year && !$S)
{
// วันปัจจุบัน กรอบสีแดง ใส่ $Tmonth หรือ $Tyear เพื่อให้ส่งค่าเดือน ปี เป็นภาษาไทย
// echo "<td class=\"menu_calender\" onmouseover=\"className='menu_calender-over'\" onmouseout=\"className='menu_calender'\" style='border:1px solid red;' align='center'><a href = '?S=1&Sday=$day&Smonth=$month&Syear=$year'>$day</a></td>";
echo "<td class=\"menu_calender\" onmouseover=\"className='menu_calender-over'\" onmouseout=\"className='menu_calender'\" style='border:1px solid red;' align='center'><a href = '?S=1&Sday=$day&Smonth=$month&Syear=$year'>$day</a></td>";
}
else//วันธรรมดา
{
if($Sday==$day && $Smonth==$month && $Syear==$year && $S)
{
// ใส่กรอบสีแดงวันที่ถูกเลือก
echo "<td class=\"menu_calender\" onmouseover=\"className='menu_calender-over'\" onmouseout=\"className='menu_calender'\" style='border:1px solid red;' align='center'><a href = '?S=1&Sday=$day&Smonth=$month&Syear=$year'>$day</a></td>";
// $select_date=($year+"-"+$month+"-"+$day);
}
else
{
echo"<td class=\"menu_calender\" onmouseover=\"className='menu_calender-over'\" onmouseout=\"className='menu_calender'\" style='border:1px solid #F5EAFF;' align='center'><a href = '?S=1&Sday=$day&Smonth=$month&Syear=$year'>$day</a></td>";
}
}
if($weekday==7 and $day <> $last_days){echo '<tr></tr>';$weekday=0;}
$day++;
$weekday++;
}
while($weekday<=7)
{
echo'<td> </td>';
$weekday++;
}
?>
</tr>
<tr>
<td colspan="7" align="center" valign="middle" style="padding-top:10px;">
<center>
<? $m_today= date('m'); $y_today= date('Y');?>
- <a href="?Nmonth=<? echo"$m_today";?>&Nyear=<? echo"$y_today ";?>"><font size="2">กลับสู่วันที่ปัจจุบัน</font></a> -
</center>
</td>
</tr>
</table>
Tag : - - - -
|
|
|
|
|
|
Date :
2010-02-16 14:23:26 |
By :
oasiis |
View :
952 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ช่วยดูให้หน่อยครับ
|
|
|
|
|
Date :
2010-02-19 08:30:26 |
By :
oasiis |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มาดูอีกคนแล้วครับ ดูแล้วไม่เป็นเหมือนกันอ่ะ
|
|
|
|
|
Date :
2010-07-12 13:35:53 |
By :
autum25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|