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 > ขอคำแนะนำ เรื่อง ปฎิทินแสดงข้อมูลจากฐานข้อมูล MySql ครับ



 

ขอคำแนะนำ เรื่อง ปฎิทินแสดงข้อมูลจากฐานข้อมูล MySql ครับ

 



Topic : 080525



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



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




ผมนำปฎิทินมาใช้แสดงข้อมูลจากฐานข้อมูลครับ จากรูปด้านล่างนะครับถ้าวันไหนมีการนัด ในปฎิทินก็จะเป็นสีเขียว ทีนี้ ที่ผมทำอยู่พอคลิกที่ วันที่
ที่มีการนัด ก็จะได้ค่าวันที่นั้นมา ผมก็จะนำเอาค่าวันที่ตรงนั้นไปเป็นตัวเช็คค่าในฐานข้อมูลเพื่อนำข้อมูลการนัดหมายมาแสดง

สิ่งที่ผมต้องการตอนนี้คือ ผมอยากส่งค่าวันที่ไปหน้าใหม่ หรือ ขึ้นหน้าป๊อปอัพใหม่ขึ้นมา ผมควรใส่โค้ดอะไรลงไปในโค้ดของปฎิทินครับ
หรือผมควรศึกษาจากอะไรครับ ขอขอบคุณไว้ล่วงหน้านะครับ

1.1


ฐานข้อมูลครับ

Code
CREATE TABLE `stbooking` (
`Id` int(4) unsigned zerofill NOT NULL auto_increment,
`Date` date NOT NULL,
`Time` varchar(20) NOT NULL,
`Detail` varchar(30) NOT NULL,
`Status` int(1) NOT NULL,
`TcID` int(4) unsigned zerofill NOT NULL,
`TcName` varchar(100) NOT NULL,
`StID` int(4) unsigned zerofill NOT NULL,
`StName` varchar(100) NOT NULL,
`StPhone` int(10) unsigned zerofill NOT NULL,
PRIMARY KEY (`Id`)
) ENGINE=MyISAM DEFAULT CHARSET=tis620 AUTO_INCREMENT=127 ;

--
-- dump ตาราง `stbooking`
--

INSERT INTO `stbooking` VALUES (0126, '2012-07-14', '14.30-15.00', '312', 0, 0006, 'อ.ดร.ปานจิตร หลงประดิษฐ์', 0001, 'กิตติพงศ์ สมศรี', 0840749571);
INSERT INTO `stbooking` VALUES (0125, '2012-07-18', '12.30-13.00', '333', 0, 0006, 'อ.ดร.ปานจิตร หลงประดิษฐ์', 0003, 'อิทธินันท์ เจตน์จำลอง', 0864514241);
INSERT INTO `stbooking` VALUES (0124, '2012-07-18', '08.30-09.00', '321', 0, 0006, 'อ.ดร.ปานจิตร หลงประดิษฐ์', 0004, 'อนันต์ พรายแสง', 0815427458);
INSERT INTO `stbooking` VALUES (0123, '2012-07-07', '12.00-12.30', '333', 0, 0007, 'อ.กรกรต เจริญผล', 0002, 'ขนิษฐา ด้วงกลึง', 0891534065);
INSERT INTO `stbooking` VALUES (0122, '2012-07-18', '11.30-12.00', '313', 0, 0006, 'อ.ดร.ปานจิตร หลงประดิษฐ์', 0001, 'กิตติพงศ์ สมศรี', 0840749571);
INSERT INTO `stbooking` VALUES (0121, '2012-07-25', '10.30-11.00', 'ห้องพักอาจารย์', 0, 0007, 'อ.กรกรต เจริญผล', 0004, 'อนันต์ พรายแสง', 0815427458);
INSERT INTO `stbooking` VALUES (0120, '2012-07-13', '11.30-12.00', '313', 0, 0006, 'อ.ดร.ปานจิตร หลงประดิษฐ์', 0001, 'กิตติพงศ์ สมศรี', 0840749571);





โค้ดปฎิทินครับ

Code (PHP)
 <?php
$hostname="localhost";
$user="root";
$passwd="root";
$dbname = "dbBooking";
$tbname="stbooking";
mysql_connect($host,$user,$passwd) or die("ติดต่อ Host ไม่ได้");
mysql_select_db($dbname) or die("ติดต่อฐานข้อมูลไม่ได้");

class Calendar
{
    /*
        Constructor for the Calendar class
    */
    function Calendar()
    {
    }
    
    
    /*
        Get the array of strings used to label the days of the week. This array contains seven 
        elements, one for each day of the week. The first entry in this array represents Sunday. 
    */
    function getDayNames()
    {
        return $this->dayNames;
    }
    

    /*
        Set the array of strings used to label the days of the week. This array must contain seven 
        elements, one for each day of the week. The first entry in this array represents Sunday. 
    */
    function setDayNames($names)
    {
        $this->dayNames = $names;
    }
    
    /*
        Get the array of strings used to label the months of the year. This array contains twelve 
        elements, one for each month of the year. The first entry in this array represents January. 
    */
    function getMonthNames()
    {
        return $this->monthNames;
    }
    
    /*
        Set the array of strings used to label the months of the year. This array must contain twelve 
        elements, one for each month of the year. The first entry in this array represents January. 
    */
    function setMonthNames($names)
    {
        $this->monthNames = $names;
    }
    
    
    
    /* 
        Gets the start day of the week. This is the day that appears in the first column
        of the calendar. Sunday = 0.
    */
      function getStartDay()
    {
        return $this->startDay;
    }
    
    /* 
        Sets the start day of the week. This is the day that appears in the first column
        of the calendar. Sunday = 0.
    */
    function setStartDay($day)
    {
        $this->startDay = $day;
    }
    
    
    /* 
        Gets the start month of the year. This is the month that appears first in the year
        view. January = 1.
    */
    function getStartMonth()
    {
        return $this->startMonth;
    }
    
    /* 
        Sets the start month of the year. This is the month that appears first in the year
        view. January = 1.
    */
    function setStartMonth($month)
    {
        $this->startMonth = $month;
    }
    
    
    /*
        Return the URL to link to in order to display a calendar for a given month/year.
        You must override this method if you want to activate the "forward" and "back" 
        feature of the calendar.
        
        Note: If you return an empty string from this function, no navigation link will
        be displayed. This is the default behaviour.
        
        If the calendar is being displayed in "year" view, $month will be set to zero.
    */
    function getCalendarLink($month, $year)
    {
        return "";
    }
    
 
    /*
        Return the HTML for the current month
    */
    function getCurrentMonthView()
    {
        $d = getdate(time());
        return $this->getMonthView($d["mon"], $d["year"]);
    }
    

    /*
        Return the HTML for the current year
    */
    function getCurrentYearView()
    {
        $d = getdate(time());
        return $this->getYearView($d["year"]);
    }
    
    
    /*
        Return the HTML for a specified month
    */
    function getMonthView($month, $year)
    {
        return $this->getMonthHTML($month, $year);
    }
    

    /*
        Return the HTML for a specified year
    */
    function getYearView($year)
    {
        return $this->getYearHTML($year);
    }
    
    
    
    /********************************************************************************
    
        The rest are private methods. No user-servicable parts inside.
        
        You shouldn't need to call any of these functions directly.
        
    *********************************************************************************/


    /*
        Calculate the number of days in a month, taking into account leap years.
    */
    function getDaysInMonth($month, $year)
    {
        if ($month < 1 || $month > 12)
        {
            return 0;
        }
   
        $d = $this->daysInMonth[$month - 1];
   
        if ($month == 2)
        {
            // Check for leap year
            // Forget the 4000 rule, I doubt I'll be around then...
        
            if ($year%4 == 0)
            {
                if ($year%100 == 0)
                {
                    if ($year%400 == 0)
                    {
                        $d = 29;
                    }
                }
                else
                {
                    $d = 29;
                }
            }
        }
    
        return $d;
    }


    /*
        Generate the HTML for a given month
    */
    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 = $monthName . (($showYear > 0) ? " " . ($year+543) : "");
    	
    	$s .= "<table width=\"800\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" bgcolor=\"#003366\">";
    	$s .= "  <tr>";
    	$s .= "    <td bgcolor=\"#FFFFFF\">";
    	$s .= "<table class=\"calendar\" border=\"0\" width=\"100%\"  cellpadding=\"0\" cellspacing=\"1\">\n";
    	$s .= "<tr>\n";
    	$s .= "<td align=\"center\" background=\"monthBg.gif\" height=\"22\">" . (($prevMonth == "") ? "&nbsp;" : "<a href=\"$prevMonth\" title=\"เดือนก่อนนี้\">  <<  </a>")  . "</td>\n";
    	$s .= "<td align=\"center\"  background=\"monthBg.gif\"  colspan=\"5\"><font size=\"2\" face=\"Tahoma\"><center>$header</center></font></td>\n"; 
    	$s .= "<td align=\"center\"  background=\"monthBg.gif\">" . (($nextMonth == "") ? "&nbsp;" : "<center><a href=\"$nextMonth\" 
		title=\"เดือนถัดไป\">  >>   </a></center>")  . "</td>\n";
    	$s .= "</tr>\n";

    	$s .= "<tr>\n";
    	$s .= "<td align=\"center\" valign=\"top\"  background=\"dayBg.gif\" height=\"14\" width=\"14%\"><font size=\"2\" face=\"Tahoma\"><center>" . $this->dayNames[($this->startDay)%7] . "</center></font></td>\n";
    	$s .= "<td align=\"center\" valign=\"top\"  background=\"dayBg.gif\" height=\"14\" width=\"14%\"><font size=\"2\" face=\"Tahoma\"><center>" . $this->dayNames[($this->startDay+1)%7] . "</center></font></td>\n";
    	$s .= "<td align=\"center\" valign=\"top\"  background=\"dayBg.gif\" height=\"14\" width=\"14%\"><font size=\"2\" face=\"Tahoma\"><center>" . $this->dayNames[($this->startDay+2)%7] . "</center></font></td>\n";
    	$s .= "<td align=\"center\" valign=\"top\"  background=\"dayBg.gif\" height=\"14\" width=\"14%\"><font size=\"2\" face=\"Tahoma\"><center>" . $this->dayNames[($this->startDay+3)%7] . "</center></font></td>\n";
    	$s .= "<td align=\"center\" valign=\"top\"  background=\"dayBg.gif\" height=\"14\" width=\"14%\"><font size=\"2\" face=\"Tahoma\"><center>" . $this->dayNames[($this->startDay+4)%7] . "</center></font></td>\n";
    	$s .= "<td align=\"center\" valign=\"top\"  background=\"dayBg.gif\" height=\"14\" width=\"14%\"><font size=\"2\" face=\"Tahoma\"><center>" . $this->dayNames[($this->startDay+5)%7] . "</center></font></td>\n";

    	$s .= "<td align=\"center\" valign=\"top\"  background=\"dayBg.gif\" height=\"14\" width=\"14%\"><font size=\"2\" face=\"Tahoma\"><center>" . $this->dayNames[($this->startDay+6)%7] . "</center></font></td>\n";
    	$s .= "</tr>\n";
    	// We need to work out what date to start at so that the first appears in the correct column
    	$d = $this->startDay + 1 - $first;
    	while ($d > 1)
    	{
    	    $d -= 7;
    	}

        // Make sure we know when today is, so that we can use a different CSS style
        $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($d >=1 and $d <=31 )
			{
				$sql="select * from stbooking  where 1=1 AND Date='$year-$month-$d' AND Status='0' ";
				//echo $sql."<br>";
				$query=mysql_query($sql);
				$result=mysql_fetch_array($query);
			}
			else
			{
			$result="";
			}
				if($result)
				{
				$link="?month=$_GET[month]&year=$_GET[year]&date=$result[Date]";
				$title="เลือกวันเพื่อดูข้อมูล";
				}
				else
				{
				$link="";
				$title="";
				}	
				if($result != "")
				{
				$bgcolor="CCFF00";
				}
				else if(($i ==0 or $i == 6) && ($d > 0 && $d <= $daysInMonth))
				{
				$bgcolor="FADCC1";
				}
				else if($d > 0 && $d <= $daysInMonth)
				{
				$bgcolor="E0E0E0";				
				}
				else
				{
				$bgcolor="EEEEEE";
				}
    	        $s .= "<td class=\"$class\" align=\"right\" height=\"40\" bgcolor=\"$bgcolor\" title=\"$title\"><font size=\"6\" face=\"Tahoma\"><center>";       
    	        if ($d > 0 && $d <= $daysInMonth)
    	        {   	            
    	            $s .= (($link == "") ? $d : "<center><a href=\"$link\">$d</a></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;
    }

    /* 
        The start day of the week. This is the day that appears in the first column
        of the calendar. Sunday = 0.
    */
    var $startDay = 0;

    /* 
        The start month of the year. This is the month that appears in the first slot
        of the calendar in the year view. January = 1.
    */
    var $startMonth = 1;

    /*
        The labels to display for the days of the week. The first entry in this array
        represents Sunday.
    */
    var $dayNames = array("อาทิตย์", "จันทร์", "อังคาร", "พุธ", "พฤหัสบดี", "ศุกร์", "เสาร์");
    
    /*
        The labels to display for the months of the year. The first entry in this array
        represents January.
    */
    var $monthNames = array("มกราคม", "กุมภาพันธ์", "มีนาคม", "เมษายน", "พฤษภาคม", "มิถุนายน",
                            "กรกฏาคม", "สิงหาคม", "กันยายน", "ตุลาคม", "พฤศจิกายน", "ธันวาคม");
                            
                            
    /*
        The number of days in each month. You're unlikely to want to change this...
        The first entry in this array represents January.
    */
    var $daysInMonth = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    
}

class MyCalendar extends Calendar
{
    function getCalendarLink($month, $year)
    {
        // Redisplay the current page, but with some parameters
        // to set the new month and year
        $s = getenv('SCRIPT_NAME');
        return "$s?month=$month&year=$year";
    }
}
?>
      <?php
// If no month/year set, use current month/year
 
$d = getdate(time());

if ($month == "")
{
    $month = $d["mon"];
}

if ($year == "")
{
    $year = $d["year"];
}

$cal = new MyCalendar;
echo $cal->getMonthView($month, $year)
?>
<? echo $date; ?>





Tag : PHP, MySQL, JavaScript, Ajax, jQuery









ประวัติการแก้ไข
2012-07-03 12:56:24
2012-07-03 13:04:22
2012-07-03 13:45:33
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-07-03 12:54:59 By : Jo Cs.1 View : 1642 Reply : 4
 

 

No. 1



โพสกระทู้ ( 1,521 )
บทความ ( 2 )

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

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

อันนี้ใช้ Tooltip

Tooltip






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-07-03 13:12:33 By : Krungsri
 


 

No. 2



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



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


ขอบคุณ คุณKrungsri นะครับ แต่ผมอยากได้แบบรูปด้านล่างนะครับ ในกรอบสีแดงนะครับ ผมอยากให้ไปอยู่ในหน้าใหม่ครับ

ปภิทิน
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-07-03 13:41:37 By : Jo Cs.1
 

 

No. 3



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



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


คุณ Krungsri ผมขอโค๊ดหน้าปฏิทิน กับ โค๊ดหน้าฐานข้อมูลได้ป่าวครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-13 16:03:38 By : Sarunkonn
 


 

No. 4

Guest


สนับสนุนครับ อยากรู้เหมือนกัน
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-01-02 14:50:23 By : ต๋อย
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ขอคำแนะนำ เรื่อง ปฎิทินแสดงข้อมูลจากฐานข้อมูล MySql ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 อัตราราคา คลิกที่นี่