 |
ดู code ให้ทีครับ มันใช้ รันกับ PHP Version 5.3.8 ไม่ได้นะครับ ? |
|
 |
|
|
 |
 |
|
code ด้านล่างนี้ เป็น code event calendar ครับ สามารถ รันบน PHP Version 5.2.6 ได้นะครับ...
ปัญหาคือ มันไม่สามารถ รันบน PHP Version 5.3.8 ได้นะครับ รบกวนผู้รู้ดูให้ทีครับ ?
ขอบคุณมากครับ
Code (PHP)
<?
mysql_connect("localhost","root","");
mysql_select_db("calendar") or die(mysql_error());
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=\"170\" 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 == "") ? " " : "<a href=\"$prevMonth\" title=\"à´×͹¡è͹¹Õé\"><img src=\"dot10.gif\" border=\"0\"></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 == "") ? " " : "<center><a href=\"$nextMonth\" title=\"à´×͹¶Ñ´ä»\"><img src=\"dot09.gif\" border=\"0\"></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 activity where 1=1 and ACTIVITY_DATE='$year-$month-$d' ";
//echo $sql."<br>";
$query=mysql_query($sql);
$result=mysql_fetch_array($query);
}
else
{
$result="";
}
if($result)
{
$link="?month=$_GET[month]&year=$_GET[year]&id=$result[ACTIVITY_ID]";
$title="$result[ACTIVITY_SUBJECT]";
}
else
{
$link="";
$title="";
}
if($result != "")
{
$bgcolor="FFCCFF";
}
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=\"20\" bgcolor=\"$bgcolor\" title=\"$title\"><font size=\"1\" 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";
}
}
?>
<?
// 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);
?>
Tag : PHP, MySQL
|
|
 |
 |
 |
 |
Date :
2011-09-26 15:44:39 |
By :
p_น้อง |
View :
1216 |
Reply :
10 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาเป็นว่ามัน Error ตรงไหนครับ หรือว่าตรงไหนไม่ทำงานก็ไปดูตรงนั้นครับ 
|
 |
 |
 |
 |
Date :
2011-09-26 16:46:32 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันไม่สามารถ คลิก เลื่อนไป เดือน ถัดไป หรือ คลิกเลื่อนย้อนหลัง ได้นะครับ......
|
 |
 |
 |
 |
Date :
2011-09-26 16:52:16 |
By :
p_น้อง |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลองไล่ดูแล้วครับ บรรทัด ด้านล่างนี้ มัน ไม่แสดง ผล บน PHP Version 5.3.8 นี้นะครับ ผมควรปรับอย่างไรดีครับ ?
if ($showYear == 1)
{
$prevMonth = $this->getCalendarLink($prev[0], $prev[1]);
$nextMonth = $this->getCalendarLink($next[0], $next[1]);
}
else
{
$prevMonth = "";
$nextMonth = "";
}
|
 |
 |
 |
 |
Date :
2011-09-26 16:59:34 |
By :
p_น้อง |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โค้ดนี้ไม่น่าจะเกี่ยวกับรันใน 5.3 ไม่ได้นะ มันแค่ if เฉยๆ
ถ้ามันรันไม่ได้มันควรจะมี error ก็เอา error มาจะได้เช็คตาม error
ถ้า error ไม่แสดงก็เพราะว่าไม่ได้ปรับ php.ini สำหรับ development ให้ไปปรับแก้ให้มันแสดง error ทั้งหมด
|
 |
 |
 |
 |
Date :
2011-09-26 18:20:27 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมว่าน่าจะเกี่ยวตรง register_global = Off/On ครับ ลองดูตรงที่ผ่านตัวแปร $_GET ครับ หรือไม่แก้ให้เป็น On ก็น่าจะได้ครับ (แต่ไม่แนะนำ)
|
 |
 |
 |
 |
Date :
2011-09-26 20:59:06 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากๆนะครับที่ช่วยตอบคำถามให้นะครับ
ปัจจุบันใช้เครื่อง ทั้ง 2 เครื่อง test code ชุดเดียวกันนะครับ
- เครื่องที่ 1 รันได้ตามปกติใช้ PHP Version 5.2.6
- เครื่องที่ 2 รันแล้ว เลื่อน เดือน เดินหน้าถอยหลังไม่ได้นะครับ ค่า $_GET ที่ url ไม่แสดงผล ไม่มี error ใดๆเกิดขึ้นเลยนะครับนิ่งไปเลยเครื่องนี้ ผมใช้ PHP Version 5.3.8
รบกวนแนะนำที่ครับ ผมต้องไปแก้ตรงไหนนะครับ ให้สามารถ รันบน PHP Version 5.3.8 เพราะ ที่ server ใช้เวอชั่นนี้นะครับ
อยากแก้ code ชุดนี้ให้ได้ก่อนนะครับ
หรือถ้ามี code ปฏิทิน ที่สามารถ แสดงผลวันที่ต้องการจาก mysql ได้ แนะนำบ้างนะครับ
|
 |
 |
 |
 |
Date :
2011-09-26 21:26:29 |
By :
p_น้อง |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าเปิดให้แสดง error
ปกติแล้วถ้ารันบน PHP Version 5.3.8 ไม่ได้ มันจะแสดง error ว่าไม่รองรับนะ เช่น ผมลอง mysql_db_query มันก็เตือนว่าไม่รองรับนะ
|
 |
 |
 |
 |
Date :
2011-09-26 23:39:32 |
By :
onedan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากๆ ครับที่ช่วย ตอบๆ ให้ และให้ความรู้มาอ่านมากมาย....
ผมลอง เข้าไป ดู ที่ php.ini บน server register_global = off แต่เครื่องที่ผมใช้ test register_global = on มันเลยรันบนเครื่อง test ได้
ซึ่งน่าจะ เป็นเพราะตัวแปรที่ใช้ เขียนไม่ถูกต้อง และ code ที่ผมใช้นี้ ผมเอามาจากใน internet อีกทีนึงนะครับ
ส่วนวิธีการแก้ไข ผมได้ทำการแก้ไขแบบ อ้อมๆ โดยการหา code มา convert เฉพาะหน้า ที่มีปัญหาไปก่อนนะครับ แล้วคราวหลังค่อยมาไล่แก้ตัวแปรให้ถูกต้องอีกทีนะครับ ^^!!
|
 |
 |
 |
 |
Date :
2011-09-27 09:03:02 |
By :
p_น้อง |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|