Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ช่วยแก้โค๊ดหน่อยครับ คือผมต้องการให้ปฎิทินแสดงตารางวันปัจจุบัน สี แตกต่างจากวันทั่วไป



 

ช่วยแก้โค๊ดหน่อยครับ คือผมต้องการให้ปฎิทินแสดงตารางวันปัจจุบัน สี แตกต่างจากวันทั่วไป

 



Topic : 061129



โพสกระทู้ ( 61 )
บทความ ( 0 )



สถานะออฟไลน์




calendar

ช่วยดูโค๊ดหน่อยครับ คือผมต้องการให้วันปัจจุบัน ตารางมีสีที่ต่างจากวันอื่นๆๆ
ช่วงบรรทัดที่ 183-200

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" />
<title>ปฏิทินกิจกรรม</title>
<script type="text/javascript">
 function Submit(form) { form.submit(); }
</script>
</head>
<body>
   <?
include("connect.php");
class Calendar
{
     function getDayNames()
    {
        return $this->dayNames;
    }
    function setDayNames($names)
    {
        $this->dayNames = $names;
    }
    function getMonthNames()
    {
        return $this->monthNames;
    }
    function setMonthNames($names)
    {
        $this->monthNames = $names;
    }
    function getStartDay()
    {
        return $this->startDay;
    }
    function setStartDay($day)
    {
        $this->startDay = $day;
    }
    function getStartMonth()
    {
        return $this->startMonth;
    }
    function setStartMonth($month)
    {
        $this->startMonth = $month;
    }
     function getCalendarLink($month, $year)
    {
        return "";
    }
     function getCurrentMonthView()
    {
        $d = getdate(time());
        return $this->getMonthView($d["mon"], $d["year"]);
    }
     function getCurrentYearView()
    {
        $d = getdate(time());
        return $this->getYearView($d["year"]);
    }
     function getMonthView($month, $year)
    {
        return $this->getMonthHTML($month, $year);
    }
     function getYearView($year)
    {
        return $this->getYearHTML($year);
    }
    
        //เกี่ยวกับวันที่
     function getDaysInMonth($month, $year)
    {
        if ($month < 1 || $month > 12)
        {
            return 0;
        }
   
        $d = $this->daysInMonth[$month - 1];
   
        if ($month == 2)
        {
            
            if ($year%4 == 0)
            {
                if ($year%100 == 0)
                {
                    if ($year%400 == 0)
                    {
                        $d = 29;
                    }
                }
                else
                {
                    $d = 29;
                }
            }
        }
    
        return $d;
    }


    function getMonthHTML($m, $y, $showYear = 1)
    {
        $s = "";
        $a = $this->adjustDate($m, $y);
        $month = $a[0];
        $year = $a[1];        
        $daysInMonth = $this->getDaysInMonth($month, $year);
    	$date = getdate(mktime(12, 0, 0, $month, 1, $year));
    	$first = $date["wday"];
    	$monthName = $this->monthNames[$month - 1];
    	$prev = $this->adjustDate($month - 1, $year);
    	$next = $this->adjustDate($month + 1, $year);
    	    if ($showYear == 1)
    	{
    	    $prevMonth = $this->getCalendarLink($prev[0], $prev[1]);
    	    $nextMonth = $this->getCalendarLink($next[0], $next[1]);
    	}
    	else
    	{
    	    $prevMonth = "";
    	    $nextMonth = "";
    	}
    	
    	$header = $cs=$monthName . $c=(($showYear > 0) ? " " . ($year+543) : "");
		$s .= "<table width=\"560\" border=\"0\"cellpadding=\"0\" cellspacing=\"0\">";
		
    	$s .= "  <tr>";
    	$s .= "    <td>";
		$s .= "<table class=\"calendar\" border=\"1\" bgcolor=\"#FFFFFF\" bordercolor=\"white\"         width=\"100%\"  cellpadding=\"0\" cellspacing=\"0\">\n";
    	$s .= "<tr>\n";
    	$s .= "<td  height=\"40\" colspan=\"7\"  align=\"center\"  bgcolor=\"#FFFFFF\">
	    ". (($prevMonth == "") ? "&nbsp;" : "
		<a href=\"$prevMonth\" title=\"เดือนก่อนนี้\"><img src=\"piccal/pre.gif\"></a>")  .        "
	                                   $header
		" . (($nextMonth == "") ? "&nbsp;" : "
		<a href=\"$nextMonth\" title=\"เดือนถัดไป\"><img src=\"piccal/next.gif\"></a>")  .        "
		</td>\n"; 
    	
		
    	$s .= "</tr>\n";
    	/*#############################################################################################
		                                  กำหนดช่องวันที่่ของแต่ละเดือน                  
		  #############################################################################################
		*/
    	$s .= "<tr hieght=20 bgcolor=\"#FF9900\">\n";
    	$s .= "<td align=\"center\" height=\"30\" valign=\"middle\" height=\"14\" width=\"14%\"><font size=\"3\"  face=\"Tahoma\"><center>"
		. $this->dayNames[($this->startDay)%7] . "</center></font></td>\n";
    	$s .= "<td align=\"center\" valign=\"middle\"  height=\"14\" width=\"14%\"><font size=\"3\"  face=\"Tahoma\"><center>"
	    . $this->dayNames[($this->startDay+1)%7] . "</center></font></td>\n";
    	$s .= "<td align=\"center\" valign=\"middle\"  height=\"14\" width=\"14%\"><font size=\"3\"  face=\"Tahoma\"><center>" 
		. $this->dayNames[($this->startDay+2)%7] . "</center></font></td>\n";
    	$s .= "<td align=\"center\" valign=\"middle\"  height=\"14\" width=\"14%\"><font size=\"3\"  face=\"Tahoma\"><center>" 
		. $this->dayNames[($this->startDay+3)%7] . "</center></font></td>\n";
    	$s .= "<td align=\"center\" valign=\"middle\"  height=\"14\" width=\"14%\"><font size=\"3\"  face=\"Tahoma\"><center>" 
		. $this->dayNames[($this->startDay+4)%7] . "</center></font></td>\n";
    	$s .= "<td align=\"center\" valign=\"middle\"  height=\"14\" width=\"14%\"><font size=\"3\"  face=\"Tahoma\"><center>" 
		. $this->dayNames[($this->startDay+5)%7] . "</center></font></td>\n";
    	$s .= "<td align=\"center\" valign=\"middle\"  height=\"14\" width=\"14%\"><font size=\"3\"  face=\"Tahoma\"><center>"
		 . $this->dayNames[($this->startDay+6)%7] . "</center></font></td>\n";
		 //########################################################################
		 //                          จบการกำหนดช่องวันที่่ของแต่ละเดือน                  
    	$s .= "</tr>\n";
    	$d = $this->startDay + 1 - $first;
    	while ($d > 1)
    	{
    	    $d -= 7;
    	}
        $today = getdate(time());
    	while ($d <= $daysInMonth)
    	{
    	    $s .= "<tr>\n";  
			
					    
    	    
    	    for ($i = 0; $i < 7; $i++)
    	    {
        $class = ($year == $today["year"] && $month == $today["mon"] && $d == $today["mday"]) ?         "calendarToday" : "calendar";
			    
            
				if(($i ==1) && ($d > 0 && $d <= $daysInMonth))
				 //##########################################################################
				 //                                ลักษณะสีของตาราง
				{
				$bgcolor="piccal/ACT.jpg ";
				}
				else if($d > 0 && $d <= $daysInMonth)
				{
				$bgcolor="piccal/DAY.jpg";				
				}
                 else if ($d > 0 && $d==date("d"))
				{
				$bgcolor="";  
                                } 
				else
				{
				$bgcolor="piccal/free.jpg";
				}
				//###############################################################################
				//                             จบการกำหนดลักษณะสีของตาราง
    	        $s .= "<td class=\"$class\" align=\"right\" height=\"80\" background=\"$bgcolor\"                 title=\"$title\"><font size=\"2\" face=\"Tahoma\"><center>";       
    	        if ($d > 0 && $d <= $daysInMonth)
    	        {   	            
    	            $s .= "<b>".(($link == "") ? $d : "</b><center><center><b>$d</b></center><font                    color=\"blue\">
					</font></center>");
    	        }
    	        else
    	        {
    	            $s .= "";
    	        }
      	        $s .= "<center></font></td>\n";     
        	    $d++;
    	    }
    	    $s .= "</tr>\n";    
    	}
    	$s .= "</table>\n";
    	$s .= "</td>";
    	$s .= "</tr>";
    	$s .= "</table>";
	return $s;  	
    }
    function adjustDate($month, $year)
    {
        $a = array();  
        $a[0] = $month;
        $a[1] = $year;
         while ($a[0] > 12)
        {
            $a[0] -= 12;
            $a[1]++;
        }
         while ($a[0] <= 0)
        {
            $a[0] += 12;
            $a[1]--;
        }
        return $a;
    }

	var $startDay = 0;
    var $startMonth = 1;
    var $dayNames = array("อาทิตย์", "จันทร์", "อังคาร", "พุธ", "พฤหัส", "ศุกร์", "เสาร์");
    var $monthNames = array("มกราคม", "กุมภาพันธ์", "มีนาคม", "เมษายน", "พฤษภาคม", "มิถุนายน",
                            "กรกฏาคม", "สิงหาคม", "กันยายน", "ตุลาคม", "พฤศจิกายน", "ธันวาคม");
    var $daysInMonth = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    }
class MyCalendar extends Calendar
{ function getCalendarLink($month, $year)
    {
        $s = getenv('SCRIPT_NAME');
        return "$s?month=$month&year=$year";
    }
}
?>
<?
 $d = getdate(time());
 if ($month == "")
{
    $month = $d["mon"];
}
if ($year == "")
{
    $year = $d["year"];
}
$cal = new MyCalendar;
echo $cal->getMonthView($month, $year);

?>

</body>
</html>






Tag : PHP









ประวัติการแก้ไข
2011-06-03 01:28:57
2011-06-03 01:30:39
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-06-03 01:27:32 By : kuzaifi View : 3936 Reply : 5
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ดูแล้วไม่ยากเลยน่ะครับ แทรก if ใน Loop ที่มีการสร้างตารางครับ ถ้าตรงกับวันปัจจุบัน ก็ให้ ใส่ bgcolor ให้กับ table ครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-03 08:44:59 By : webmaster
 


 

No. 2



โพสกระทู้ ( 61 )
บทความ ( 0 )



สถานะออฟไลน์


คับ ผมลองไม่รู้จะใช้เงือนไขอะไรครับ
ลองใช้ if(date("d")==$d) แล้ว มันไม่เกิดอะไรเลยครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-03 12:11:21 By : kuzaifi
 

 

No. 3



โพสกระทู้ ( 61 )
บทความ ( 0 )



สถานะออฟไลน์


ช่วยดูให้ผมหน่อยน่ะครับ แก้มาหายวันแล้วไม่ได้ซะที
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-03 21:43:25 By : kuzaifi
 


 

No. 4



โพสกระทู้ ( 3,844 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Twitter Facebook

อจจะซับซ้อนไปนิด แต่ตอนนี้ผมได้แค่นี้แหล่ะครับ ส่วนสีตารางผมคิดใส่เอง ให้เห็นความแตกต่างเฉยๆน่ะครับ
Code (PHP)
if(($i ==1) && ($d > 0 && $d <= $daysInMonth))
//##########################################################################
// ลักษณะสีของตาราง
{
	if($d > 0 && $d <= $daysInMonth)
	{
	$bgcolor="#CCCCCC";
	}
	else
	{
	       $my_date=(date('d')+$daysInMonth)-$daysInMonth;//  Fixe รูปแบบวันที่ จาก 0x เป็น x **ยังไม่ต้องงงน่ะครับ
    	   $my_month=(date('m')+$month)-$month;//Fixe รูปแบบเดือน จาก 0x เป็น x **ยังไม่ต้องงงเหมือนกันน่ะครับ
  	     $my_st_date=$year."".$my_month."".$my_date; /// สร้างวันที่ปัจจุบัน yyyymmdd
	       $make_st_date=$year."".$month."".$d; // สร้างวันที่จากสคริปต์ yyyymmdd

	   	     if($my_st_date == $make_st_date) // เปรียบเทียบค่าวันที่ ครับ
		{
		$bgcolor="#336666";
		}
		else
		{
		$bgcolor="#0099FF";
		}
	}
}
else
{
$bgcolor="#FF0000";
}
//###############################################################################



ประวัติการแก้ไข
2011-06-03 23:53:02
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-03 23:46:52 By : mangkunzo
 


 

No. 5



โพสกระทู้ ( 61 )
บทความ ( 0 )



สถานะออฟไลน์


ขอขอบคุณครับ mangkunzo
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-04 02:31:35 By : kuzaifi
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยแก้โค๊ดหน่อยครับ คือผมต้องการให้ปฎิทินแสดงตารางวันปัจจุบัน สี แตกต่างจากวันทั่วไป
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่