ปฏิทินกิจกรรม ทำปฏิทิน จะทำไงในการดึงข้อมูลจาก base ออกมา show แล้วเข้าไป แก้ไขได้อะครับ
ทำปฏิทิน จะทำไงในการดึงข้อมูลจาก base ออกมา show แล้วเข้าไป แก้ไขได้อะครับ
index.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" />
<link href="style/style.css" rel="stylesheet" type="text/css" />
<title>CALENDER</title>
</head>
<body>
<center>
<p>
<?php
## +---------------------------------------------------------------------------+
## | 1. Creating & Calling: |
## +---------------------------------------------------------------------------+
// invlude calendar class
require_once("calendar.php");
// create calendar object
$objCalendar = new Calendar();
## +---------------------------------------------------------------------------+
## | 2. General Settings: |
## +---------------------------------------------------------------------------+
## *** set calendar width and height ความกว้าง ความยาว
$objCalendar->SetCalendarDimensions("800px", "500px");
## *** set week day name length - "short" or "long"
$objCalendar->SetWeekDayNameLength("long");
## *** set start day of week: from 1 (Sanday) to 7 (Saturday) <---
$objCalendar->SetWeekStartedDay("1");
## +---------------------------------------------------------------------------+
## | 3. Draw Calendar: |
## +---------------------------------------------------------------------------+
$objCalendar->Show();
?>
</p>
<form id="form1" name="form1" method="post" action="add.php">
<label></label>
<label>
<input type="submit" name="button" id="button" value="เพิ่มงาน" />
</label>
</form>
<form id="form2" name="form2" method="post" action="edit.php">
<label>
<input type="submit" name="button2" id="button2" value="แสดงงานทั้งหมด" />
</label>
</form>
<p> </p>
</center>
</body>
</html>
calendar.php
<title>CALENDAR</title>
<?php
class Calendar{
private $arrWeekDays;
private $arrMonths;
private $arrViewTypes;
private $defaultView;
private $defaultAction;
private $isDrawNavigation;
private $crLt;
private $caption;
private $calWidth;
private $calHeight;
private $cellHeight;
private $result;
function show_event($result)
{
include("connect.php");
$sql = "SELECT events, work_id
FROM work
";
$dbquery = mysql_db_query($DBname, $sql) or die("Can't Query");
while($result = mysql_fetch_array($dbquery)){
$events = $result["events"];
$work_id = $result["work_id"];
$sql2 = "SELECT detail_id,days
FROM detail
";
$dbquery2 = mysql_db_query($DBname, $sql2) or die("Can't Query");
while($result2 = mysql_fetch_array($dbquery2)){
$detail_id = $result2["detail_id"];
$days = $result2["days"];
}
}
echo "<font class=\"eventLink\">-<a href=\"form_edit.php?work_id=<?=$work_id?>&detail_id=<?=$detail_id?>\"class=\"eventLink\ ><?=$events?></a></font> <br>";
echo 'work';
}
function __construct()
{
// possible values 1,2,....7 มี sunday
$this->weekStartedDay = 1;
//ให้มีการขึ้นชื่อ วันด้านบน
$this->arrWeekDays = array();
$this->arrWeekDays[0] = array("short"=>"Sun", "long"=>"Sunday");
$this->arrWeekDays[1] = array("short"=>"Mon", "long"=>"Monday");
$this->arrWeekDays[2] = array("short"=>"Tue", "long"=>"Tuesday");
$this->arrWeekDays[3] = array("short"=>"Wed", "long"=>"Wednesday");
$this->arrWeekDays[4] = array("short"=>"Thu", "long"=>"Thursday");
$this->arrWeekDays[5] = array("short"=>"Fri", "long"=>"Friday");
$this->arrWeekDays[6] = array("short"=>"Sat", "long"=>"Satarday");
//มีชื่อเดือนให้เลือกใน Listbox
$this->arrMonths = array();
$this->arrMonths["1"] = "January";
$this->arrMonths["2"] = "February";
$this->arrMonths["3"] = "March";
$this->arrMonths["4"] = "April";
$this->arrMonths["5"] = "May";
$this->arrMonths["6"] = "June";
$this->arrMonths["7"] = "July";
$this->arrMonths["8"] = "August";
$this->arrMonths["9"] = "September";
$this->arrMonths["10"] = "October";
$this->arrMonths["11"] = "November";
$this->arrMonths["12"] = "December";
//มีให้เลือกเดือนกับปีที่มุมขวา
$this->arrViewTypes = array();
$this->arrViewTypes["monthly"] = "Monthly";
$this->arrViewTypes["yearly"] = "Yearly";
}
function show()
{
//ตัว next back ปี กับ เดือน ด้านบน
$this->GetCurrentParameters();
$this->DrawJsFunctions();
//ตัวเรียก CSS
echo "<div id='calendar' style='width:".$this->calWidth.";'>".$this->crLt;
// draw calendar header ตัวเสดง TODAY และ ตัวเลือก เดือน กับ ปี ด้านบน
echo "<table id='calendar_header'>".$this->crLt;
echo "<tr>";
echo "<th class='caption_left'>".$this->DrawTodayJumper(false)."</th>";
echo "<th class='caption'>".$this->caption."</th>";
echo "<th class='types_changer'>".$this->DrawTypesChanger(false)."</th>";
echo "</tr>".$this->crLt;
echo "</table>";
switch($this->arrParameters["view_type"])
{
case "yearly":
$this->DrawYear();
break;
default:
case "monthly":
$this->DrawMonth();
break;
}
}
/**
* Set calendar dimensions
* @param $width
* @param $height กำหนดความกว้างความยาวของ ปฏิทิน
*/
function SetCalendarDimensions($width = "", $height = "")
{
$this->calWidth = ($width != "") ? $width : "800px";
$this->calHeight = ($height != "") ? $height : "470px";
$this->celHeight = number_format(((int)$this->calHeight)/5, "")."px";
}
/**
* Set week started day
* @param $started_day - started day of week 1...7 ให้มัน start ที่เท่าไร
*/
function SetWeekStartedDay($started_day = "1")
{
if(is_numeric($started_day) && (int)$started_day >= 1 && (int)$started_day <= 7){
}
}
/**
* Set week day name length
* @param $length_name - "short"|"long" ตัวแสเงชื่อวันด้านบน
*/
function SetWeekDayNameLength($length_name = "short")
{
if(strtolower($length_name) == "long"){
$this->weekDayNameLength = "long";
}
}
function GetCurrentParameters() //การสร้าง ว ด ป
{
$year = (isset($_GET['year']) && $this->isYear($_GET['year'])) ? $_GET['year'] : date("Y");
$month = (isset($_GET['month']) && $this->isMonth($_GET['month'])) ? $_GET['month'] : date("m");
$day = (isset($_GET['day']) && $this->isDay($_GET['day'])) ? $_GET['day'] : date("d");
$view_type = (isset($_GET['view_type']) && array_key_exists($_GET['view_type'], $this->arrViewTypes)) ? $_GET['view_type'] : "monthly";
$cur_date = getdate(mktime(0,0,0,$month,$day,$year));
include("connect.php");
$sql = "SELECT events, work_id
FROM work
";
$dbquery = mysql_db_query($DBname, $sql) or die("Can't Query");
$sql2 = "SELECT detail_id, days
FROM detail
";
$dbquery2 = mysql_db_query($DBname, $sql2) or die("Can't Query");
while($result = mysql_fetch_array($dbquery)){
$events = $result["events"];
$work_id = $result["work_id"];
while($result2 = mysql_fetch_array($dbquery2)){
$detail_id = $result2["detail_id"];
$days = $result2["days"];
}
?>
<a href="form_edit.php?work_id=<?=$work_id?>&detail_id=<?=$detail_id?>"><?=$events?></a> <br>
<?php
}
$this->arrParameters["year"] = $cur_date['year'];
$this->arrParameters["month"] = $this->ConvertToDecimal($cur_date['mon']);
$this->arrParameters["month_full_name"] = $cur_date['month'];
$this->arrParameters["day"] = $day;
$this->arrParameters["view_type"] = $view_type;
$this->arrParameters["action"] = "display";
$this->arrToday = getdate();
$this->prevYear = getdate(mktime(0,0,0,$this->arrParameters['month'],$this->arrParameters["day"],$this->arrParameters['year']-1));
$this->nextYear = getdate(mktime(0,0,0,$this->arrParameters['month'],$this->arrParameters["day"],$this->arrParameters['year']+1));
$this->prevMonth = getdate(mktime(0,0,0,$this->arrParameters['month']-1,$this->arrParameters["day"],$this->arrParameters['year']));
$this->nextMonth = getdate(mktime(0,0,0,$this->arrParameters['month']+1,$this->arrParameters["day"],$this->arrParameters['year']));
}
/**
* Draw javascript functions
*
*/
private function DrawJsFunctions()// FUNCTIONS JUMP ที่ปุ่ม Go
{
echo "<script type='text/javascript'>";
echo "
function JumpToDate(){
var jump_day = (document.getElementById('jump_day')) ? document.getElementById('jump_day').value : '';
var jump_month = (document.getElementById('jump_month')) ? document.getElementById('jump_month').value : '';
var jump_year = (document.getElementById('jump_year')) ? document.getElementById('jump_year').value : '';
var view_type = (document.getElementById('view_type')) ? document.getElementById('view_type').value : '';
__doPostBack('view', view_type, jump_year, jump_month, jump_day);
}
function JumpTo(){
alert('show_event');
}
function __doPostBack(action, view_type, year, month, day)
{
var action = (action != null) ? action : 'view';
var view_type = (view_type != null) ? view_type : 'monthly';
var year = (year != null) ? year : '".$this->arrToday["year"]."';
var month = (month != null) ? month : '".$this->ConvertToDecimal($this->arrToday["mon"])."';
var day = (day != null) ? day : '".$this->arrToday["mday"]."';
document.location.href = '".$this->arrParameters["current_file"]. "?action='+action+'&view_type='+view_type+'&year='+year+'&month='+month+'&day='+day;
}
";
echo "</script>";
}
/**
* Draw monthly calendar
*
*/
private function DrawMonth()
{
// today, first day and last day in month
$firstDay = getdate(mktime(0,0,0,$this->arrParameters['month'],1,$this->arrParameters['year']));
$lastDay = getdate(mktime(0,0,0,$this->arrParameters['month']+1,0,$this->arrParameters['year']));
///print_r($firstDay);
// Create a table with the necessary header informations
echo "<table class='month'>".$this->crLt;
echo "<tr>";
echo "<th colspan='7'>";
echo "<table class='table_navbar'>".$this->crLt;
echo "<tr>";
echo "<th class='tr_navbar_left'>
".$this->DrawDateJumper(false)."
</th>".$this->crLt;
echo "<th class='tr_navbar'>";
echo " <a href=\"javascript:__doPostBack('view', 'monthly', '".$this->prevMonth['year']."', '".$this->ConvertToDecimal($this->prevMonth['mon'])."', '".$this->arrParameters['day']."')\">««</a> ";
echo $this->arrParameters['month_full_name']." - ".$this->arrParameters['year'];
echo " <a href=\"javascript:__doPostBack('view', 'monthly', '".$this->nextMonth['year']."', '".$this->ConvertToDecimal($this->nextMonth['mon'])."', '".$this->arrParameters['day']."')\">»»</a> ";
echo "</th>".$this->crLt;
echo "<th class='tr_navbar_right'>
<a href=\"javascript:__doPostBack('view', 'monthly', '".$this->prevYear['year']."', '".$this->arrParameters['month']."', '".$this->arrParameters['day']."')\">".$this->prevYear['year']."</a> |
<a href=\"javascript:__doPostBack('view', 'monthly', '".$this->nextYear['year']."', '".$this->arrParameters['month']."', '".$this->arrParameters['day']."')\">".$this->nextYear['year']."</a>
</th>".$this->crLt;
echo "</tr>".$this->crLt;
echo "</table>".$this->crLt;
echo "</td>".$this->crLt;
echo "</tr>".$this->crLt;
echo "<tr class='tr_days'>";
for($i = $this->weekStartedDay-1; $i < $this->weekStartedDay+6; $i++){
echo "<td class='th'>".$this->arrWeekDays[($i % 7)][$this->weekDayNameLength]."</td>";
}
echo "</tr>".$this->crLt;
// Display the first calendar row with correct positioning
if ($firstDay['wday'] == 0) $firstDay['wday'] = 7;
$max_empty_days = $firstDay['wday']-($this->weekStartedDay-1);
if($max_empty_days < 7){
echo "<tr class='tr' style='height:".$this->celHeight.";'>".$this->crLt;
for($i = 1; $i <= $max_empty_days; $i++){
echo "<td class='td_empty'> </td>".$this->crLt;
}
$actday = 0;
for($i = $max_empty_days+1; $i <= 7; $i++){
$actday++;
if (($actday == $this->arrToday['mday']) && ($this->arrToday['mon'] == $this->arrParameters["month"])) {
$class = " class='td_actday'";
} else if ($actday == $this->arrParameters['day']){
$class = " class='td_selday'";
} else {
$class = " class='td'";
}
echo "<td$class>$actday</td>".$this->crLt;
}
echo "</tr>".$this->crLt;
}
//Get how many complete weeks are in the actual month
$fullWeeks = floor(($lastDay['mday']-$actday)/7);
for ($i=0;$i<$fullWeeks;$i++){
echo "<tr class='tr' style='height:".$this->celHeight.";'>".$this->crLt;
for ($j=0;$j<7;$j++){
$actday++;
if (($actday == $this->arrToday['mday']) && ($this->arrToday['mon'] == $this->arrParameters["month"])) {
$class = " class='td_actday'";
} else if ($actday == $this->arrParameters['day']){
$class = " class='td_selday'";
} else {
$class = " class='td'";
}
echo "<td$class>$actday</td>".$this->crLt;
}
echo "</tr>".$this->crLt;
}
//Now display the rest of the month
if ($actday < $lastDay['mday']){
echo "<tr class='tr' style='height:".$this->celHeight.";'>".$this->crLt;
for ($i=0; $i<7;$i++){
$actday++;
if (($actday == $this->arrToday['mday']) && ($this->arrToday['mon'] == $this->arrParameters["month"])) {
$class = " class='td_actday'";
} else {
$class = " class='td'";
}
if ($actday <= $lastDay['mday']){
echo "<td$class>$actday</td>".$this->crLt;
} else {
echo "<td class='td_empty'> </td>".$this->crLt;
}
}
echo "</tr>".$this->crLt;
}
echo "</table>".$this->crLt;
}
/**
* Draw calendar types changer
* @param $draw - draw or return
*/
private function DrawTypesChanger($draw = true)
{
foreach($this->arrViewTypes as $key => $val){
}
}
/**
* Draw today jumper
* @param $draw - draw or return
*/
private function DrawTodayJumper($draw = true)
{ // TODAT มุมซ้าย
$result = "<input class='form_button' type='button' value='Today' onclick=\"javascript:__doPostBack('".$this->defaultAction."', '".$this->defaultView."', '".$this->arrToday["year"]."', '".$this->ConvertToDecimal($this->arrToday["mon"])."', '".$this->arrToday["mday"]."')\" />";
if($draw){
echo $result;
}else{
return $result;
}
}
/**
* Draw date jumper
* @param $draw - draw or return
*/
private function DrawDateJumper($draw = true, $draw_day = true, $draw_month = true, $draw_year = true)
{
// draw days ddl
if($draw_day){ //ทำ LISTBOX วันที่
$result = "<select class='form_select' name='jump_day' id='jump_day'>";
for($i=1; $i <= 31; $i++){
$i_converted = $this->ConvertToDecimal($i);
$result .= "<option value='".$this->ConvertToDecimal($i)."' ".(($this->arrParameters["day"] == $i_converted) ? "selected='selected'" : "").">".$i_converted."</option>";
}
$result .= "</select> ";
}else{
}
// draw months ddl
if($draw_month){ //ทำ LISTBOX เดือน
$result .= "<select class='form_select' name='jump_month' id='jump_month'>";
for($i=1; $i <= 12; $i++){
$i_converted = $this->ConvertToDecimal($i);
$result .= "<option value='".$this->ConvertToDecimal($i)."' ".(($this->arrParameters["month"] == $i_converted) ? "selected='selected'" : "").">".$this->arrMonths[$i]."</option>";
}
$result .= "</select> ";
}else{
}
// draw years ddl
if($draw_year){ //ทำ LISTBOX ปี
$result .= "<select class='form_select' name='jump_year' id='jump_year'>";
for($i=$this->arrParameters["year"]-10; $i <= $this->arrParameters["year"]+10; $i++){
$result .= "<option value='".$i."' ".(($this->arrParameters["year"] == $i) ? "selected='selected'" : "").">".$i."</option>";
}
$result .= "</select> ";
}else{
$result .= "<input type='hidden' name='jump_year' id='jump_year' value='".$this->arrToday["year"]."' />";
}
//ปุ่ม GO
$result .= "<input class='form_button' type='button' value='Go' onclick='JumpTo()' />";
if($draw){
echo $result;
}else{
return $result;
}
}
////////////////////////////////////////////////////////////////////////////
// Auxilary
////////////////////////////////////////////////////////////////////////////
/**
* Check if parameters is 4-digit year
* @param $year - string to be checked if it's 4-digit year
*/
private function isYear($year = "")
{
for($i = 0; $i < 4; $i++){
if(!(isset($year[$i]) && $year[$i] >= 0 && $year[$i] <= 9)){
return false;
}
}
return true;
}
/**
* Check if parameters is month
* @param $month - string to be checked if it's 2-digit month
*/
private function isMonth($month = "")
{
for($i = 0; $i < 2; $i++){
if(!(isset($month[$i]) && $month[$i] >= 0 && $month[$i] <= 9)){
return false;
}
}
return true;
}
/**
* Check if parameters is day
* @param $day - string to be checked if it's 2-digit day
*/
private function isDay($day = "")
{
for($i = 0; $i < 2; $i++){
if(!(isset($day[$i]) && $day[$i] >= 0 && $day[$i] <= 9)){
return false;
}
}
return true;
}
/**
* Convert to decimal number with leading zero
* @param $number วัน
*/
private function ConvertToDecimal($number)
{
return (($number < 10) ? "0" : "").$number;
}
}
?>
ลักษณะของ base ชื่อว่า test ประกอบไปด้วย detail(detail_id,description,daysมีรูปแบบการเก็บเป็น2010-05-14) work (work_id,events) ให้แสดงชื่อของ event ออกมา ตามวัน days อะครับ
เข้าใจเปล่าไม่รู้Tag : - - - -
Date :
2010-04-28 09:46:48
By :
kirisaki
View :
2862
Reply :
9
ไม่มีสัญาณตอบรับ จากหมายเลขที่ท่านเรียก
Date :
2010-04-28 10:33:44
By :
kirisaki
เป็นผมจะเขียนให้ดึงข้อมูลออกมาเก็บวันค่าวันที่ตัวแปรครับ ต่อจากนั้น เราก็ใช้วันเป็นตัวกำหนด ครับ ว่าถ้าวันที่11 ให้ดึงข้อมูลวันที่11 ขึ้นมา แต่ต้องมีการกำหนดเรื่องของเดือนด้วยนะครับ ว่าเดือนไหน
ปีไหน
จะได้กำหนดวันได้ถูกต้อง ถ้าวันไหนไม่มีข้อมูลก็ไม่ให้แสดงครับ
Date :
2010-04-28 10:37:14
By :
SOUL
ลอง เอา code ไป ดูให้หน่อยได้เปล่าครับ ผมคิดจนมึนหมดแล้วอะครับ...
Date :
2010-04-28 10:49:59
By :
kirisaki
Date :
2010-04-28 13:55:31
By :
kirisaki
เงียบเหงามากมาย
Date :
2010-04-28 16:18:07
By :
kirisaki
ไม่มีใครมาตอบเลยอะ
Date :
2010-04-29 08:42:47
By :
kirisaki
ขอบคุณค่ะ
มีประโยช์มากๆๆเลยค่ะ
Date :
2011-12-23 19:37:50
By :
saatemis
โค๊ดมาแป๊ะยาวซะขนาดนี้ สัญญาณมันเลยหลุดครับ
Date :
2011-12-24 03:32:43
By :
ikikkok
Load balance : Server 05