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 > พี่ ๆ ช่วยดูโค้ดให้หน่อยครับ ไม่รู้ผิดพลาดตรงไหน เกี่ยวกับ date ครับ



 

พี่ ๆ ช่วยดูโค้ดให้หน่อยครับ ไม่รู้ผิดพลาดตรงไหน เกี่ยวกับ date ครับ

 



Topic : 054226



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

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

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




<?
$hostname = "localhost";
$username = "root";
$password = "mysql";
$dbname = "tutorial2";
$tbname= "eventcalender";
$error = "Can not connect database. Please try again later";

mysql_connect($hostname,$username,$password) or die ($error);
mysql_select_db($dbname) or die($error);


?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Event Calendar</title>
<link rel="stylesheet" type="text/css" href="table.css" />
<script type="text/javascript">
function goLastMonth(month,year){
if(month==1){
--year;
month=13 ;
}

--month
var monthstring = ""+month+"";
var monthlength = monthstring.length;
if(monthlength <= 1){
monthstring = '0'+monthstring;
}
document.location.href="<?php $_SERVER["PHP_SELF"]; ?>?month="+monthstring+"&year="+year;
}

function goNextMonth(month,year){
if(month==12){
++year;
month=0 ;
}

++month
var monthstring = ""+month+"";
var monthlength = monthstring.length;
if(monthlength <= 1){
monthstring = '0'+monthstring;
}
document.location.href="<?php $_SERVER["PHP_SELF"]; ?>?month="+monthstring+"&year="+year;
}
</script>

<style>

.today{
background-color : #fd4040;
}

.event{
background-color : #acacaf;
}

</style>
</head>


<body>
<?php
//============================

if(isset($_GET['day'])){
$day=$_GET['day'];
}

else{
$day = date ("j");
}

//--------------------------------------------------------

if(isset($_GET['month'])){
$month = $_GET['month'];
}

else{
$month = date ("n");
}

//--------------------------------------------------------

if(isset($_GET['year'])){
$year = $_GET['year'];
}
else{
$year = date ("Y")+543;
//$year = date("Y");

}

//============================

//echo $day."/".$month."/".$year ;
//ประกาศตัวแปร

$currentTimeStamp = strtotime("$year-$month-$day");
$monthName = date("F",$currentTimeStamp);

switch($monthName)
{
case "January":
$printmonth = "มกราคม";
break;
case "February":
$printmonth = "กุมภาพันธ์";
break;
case "March":
$printmonth = "มีนาคม";
break;
case "April":
$printmonth = "เมษายน";
break;
case "May":
$printmonth = "พฤษภาคม";
break;
case "June":
$printmonth = "มิถุนายน";
break;
case "July":
$printmonth = "กรกฏาคม";
break;
case "August":
$printmonth = "สิงหาคม";
break;
case "September":
$printmonth = "กันยายน";
break;
case "October":
$printmonth = "ตุลาคม";
break;
case "November":
$printmonth = "พฤศจิกายน";
break;
case "December":
$printmonth = "ธันวาคม";
break;
}

$numDays = date("t",$currentTimeStamp); // วัน/เวลาปัจจุบัน
$counter=0;

if(isset($_GET['add'])){
$title = $_POST['txttitle'];
$detail = $_POST['txtdetail'];
$eventdate = $month."/".$day."/".$year;
//$sqlinsert = "insert into eventcalender(Title,Detail,eventDate,dateAdded)values(' ".$title." ',' ".$detail." ',' ".$eventdate." ' , now() )";
$sqlinsert = "INSERT INTO `tutorial2`.`eventcalender` (`ID` ,`Title` ,`Detail` ,`eventDate` ,`dateAdded` )
VALUES (NULL , '".$title."', '".$detail."', '".$eventdate."', now());";

mysql_query("SET NAMES UTF8");
$resultinsert = mysql_query($sqlinsert);


if($resultinsert){

echo"Insert to database Success";
echo "<br>";
echo $title ;
echo "<br>";
echo $detail ;

}
else{

echo"Cannot Insert to database Success";

}

}
?>

<table border="1" align="center" class="reference">
<tr>
<th><input type='button' style='width:25px' value='<' name='previousbutton' onClick='goLastMonth(<?php echo $month.",".$year ?>);'></th>
<th colspan="5" align="center"><?php echo $printmonth." , ".$year; ?></th>
<th><input type='button' style='width:25px' value='>' name='nextbutton' onClick='goNextMonth(<?php echo $month.",".$year ?>);'></th>
</tr>
<tr>
<th width="25px">อา.</th>
<th width="25px">จ.</th>
<th width="25px">อ.</th>
<th width="25px">พ.</th>
<th width="25px">พฤ.</th>
<th width="25px">ศ.</th>
<th width="25px">ส.</th>
</tr>
<?php
echo "<tr>";

for($i=1;$i<$numDays+1;$i++,$counter++)
{
$timeStamp = strtotime("$year-$month-$i");
if($i==1){
$firstDay = date("w", $timeStamp);
for($j=0;$j < $firstDay;$j++,$counter++)
{
//blank space
echo"<th>&nbsp;</th>";
}
}
if($counter%7==0)
{ echo"</tr><tr>";

}
$monthstring = $month;
$monthlength = strlen($monthstring);
$daystring = $i;
$daylength= strlen($daystring);
if($monthlength<=1){

$monthstring= '0'.$monthstring;
}

if($daylength<=1){
$daystring= '0'.$daystring;
}
$todaysDate = date("m/d/Y");
$dateToComplare=$monthstring.'/'.$daystring.'/'.$year;
echo"<td align='center' ";
if($todaysDate==$dateToComplare){
echo"class='today' ";
}
else{
$sqlCount="select * from eventcalender where eventDate='".$dateToComplare."'";
$noOfEvent = mysql_num_rows(mysql_query($sqlCount));

if($noOfEvent>= 1){

echo"class='event'";

}

}
echo"><a href=' ".$_SESSION['PHP_SELF']."?month=". $monthstring."&day=".$daystring."&year=".$year."&v=true'>".$i. " </a></td>";
}
echo "</tr>";
?>
</table>
<?

if(isset($_GET['v'])){
echo"<a href=' ".$_SESSION['PHP_SELF']."?month=". $month."&day=".$day."&year=".$year."&v=true&f=true'>Add Event</a>";
if(isset($_GET['f'])){
include('fm_addEvent.php');
}
$sqlEvent="select * from eventcalender where eventDate='".$month."/".$day."/".$year."'";
mysql_query("SET NAMES UTF8");
$resultEvents=mysql_query($sqlEvent);
echo"<br>";
echo"<hr>";
while($events=mysql_fetch_array($resultEvents)){

echo"หัวข้อ : ".$events['Title']."<br>";
echo"รายละเอียด : ".$events['Detail']."<br>";
echo"เวลา : ".$events['eventDate']."<br>";
echo"<br>";
echo"<br>";

}
}

?>
</body>
</html>
คือผมกำลังแปลงวัน เดือน ปีให้เป็นภาษาไทยครับ



ปัญหามันมีอยู่ตรงนี้ครับ

ถ้าผมเขียนแบบนี้ ปีก็จะเป็น พ.ศ.แล้วก็เลื่อนไปปีอื่นได้ตามปกติ แต่เดือนไม่เลื่อนตาม

$year = date ("Y")+543;

แล้วก็ค้างอยู่แบบนี้ แต่ปีเลื่อนได้

มันแสดงผลแบบนี้





แต่ถ้าผมเขียนแบบนี้ ปีก็จะเป็น ค.ศ. เดือนเลื่อนไปเดือนอื่นได้ครับตามปกติ

$year = date ("Y");

ช่วยแนะนำทีว่าผมต้องทำอย่างไร แต่เท่าที่ผมดู โดยหลักการมันน่าจะได้นะครับ

คือผมอยากได้ปีเป็น พ.ศ. ครับ



Tag : PHP, MySQL









ประวัติการแก้ไข
2011-01-10 14:15:01
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-01-10 14:13:35 By : Chaan View : 823 Reply : 1
 

 

No. 1



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



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


พอเจ้าความต้องการ ของคุณนะ แต่ผมไม่เห้นภาพอ่ะ ไม่รู้อธิบายยังไง ลองไปดูการส่งค่านะครับ คุณไม่ต้องส่ง 543 ไปด้วย






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-01-12 10:37:30 By : create_ninku
 

   

ค้นหาข้อมูล


   
 

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