|
 |
|
มีปัญหาในการเรียกใช้งาน function datetime มัน Cannot redeclare datethai() เกิดจากอะไรครับ |
|
 |
|
|
 |
 |
|
Code (PHP)
มีปัญหาในการเรียกใช้งาน function datetime มัน Cannot redeclare datethai() เกิดจากอะไรครับ
Code (PHP)
function DateThai($strDate)
{
$strYear = date("Y",strtotime($strDate))+543;
$strMonth= date("n",strtotime($strDate));
$strDay= date("j",strtotime($strDate));
$strHour= date("H",strtotime($strDate));
$strMinute= date("i",strtotime($strDate));
$strSeconds= date("s",strtotime($strDate));
$strMonthCut = Array("","มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤษจิกายน","ธันวาคม");
$strMonthThai=$strMonthCut[$strMonth];
return "$strDay $strMonthThai $strYear : $strHour:$strMinute";
}
while($rs= mysql_fetch_array($objQuery )){
$date=$rs['new_date'];
<?=DateThai($date)?>
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2012-02-19 13:40:55 |
By :
chonburi f.c |
View :
1290 |
Reply :
7 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมลองดู ก็ปกติดีนี่ครับ
Code (PHP)
$date=DateThai("2012/02/20 12:00:00"); // yyyy-mm-dd hh:ii:ss
echo $date;
|
 |
 |
 |
 |
Date :
2012-02-19 14:58:31 |
By :
mangkunzo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 1 เขียนโดย : mangkunzo เมื่อวันที่ 2012-02-19 14:58:31
รายละเอียดของการตอบ ::
ผมดึงมาใช้แบบนี้ครับไม่รู้ว่ามันใส่ค่าถูกรึป่าว ผมวนลูปค่า วันที่ใน db ออกมาก่อนโดยใช้ ตัวแปล dateedit ตอนประกาศใช้แบบนี่ไม่ทราบว่าถูกรึป่าวครับ
Code (PHP)
<?=datethai($dateedit)?>
<?
while($rs= mysql_fetch_array($objQuery )){
$id=$rs['new_id'];
$title=$rs['new_title'];
$dateedit=$rs['new_date'];
function DateThai($strDate)
{
$strYear = date("Y",strtotime($strDate))+543;
$strMonth= date("n",strtotime($strDate));
$strDay= date("j",strtotime($strDate));
$strHour= date("H",strtotime($strDate));
$strMinute= date("i",strtotime($strDate));
$strSeconds= date("s",strtotime($strDate));
$strMonthCut = Array("","มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤษจิกายน","ธันวาคม");
$strMonthThai=$strMonthCut[$strMonth];
return "$strDay $strMonthThai $strYear : $strHour:$strMinute";
}
?>
|
 |
 |
 |
 |
Date :
2012-02-19 15:53:03 |
By :
auikung |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
น่าจะประกาศ DateThai ในลูปแน่เลย
|
 |
 |
 |
 |
Date :
2012-02-19 16:43:25 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 2 เขียนโดย : auikung เมื่อวันที่ 2012-02-19 15:53:03
รายละเอียดของการตอบ ::
function DateThai เอาไว้นอกลูป ครับ เอาไว้ข้างในมันทำงานไม่ถูกครับ
**อธิบายเพิ่มเติ่ม>>
Error : Cannot redeclare datethai() เกิดจากการเอา function ไปวนลูป ชื่อฟังชั่นเดิมมันถูกสร้างซ้ำ
ซึ่งโดยหลักการแล้ว ฟังชั่นใดๆต้องประกาศครัังเดียว
Code (PHP)
function DateThai($strDate)
{
$strYear = date("Y",strtotime($strDate))+543;
$strMonth= date("n",strtotime($strDate));
$strDay= date("j",strtotime($strDate));
$strHour= date("H",strtotime($strDate));
$strMinute= date("i",strtotime($strDate));
$strSeconds= date("s",strtotime($strDate));
$strMonthCut = Array("","มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤษจิกายน","ธันวาคม");
$strMonthThai=$strMonthCut[$strMonth];
return "$strDay $strMonthThai $strYear : $strHour:$strMinute";
}
while($rs= mysql_fetch_array($objQuery ))
{
$id=$rs['new_id'];
$title=$rs['new_title'];
$dateedit=$rs['new_date'];
echo datethai($dateedit)."<br>";
}
|
ประวัติการแก้ไข 2012-02-19 17:51:39
 |
 |
 |
 |
Date :
2012-02-19 17:45:52 |
By :
mangkunzo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณก็เอาออกจาก loop แค่นั้นก็ได้แล้วครับ
|
 |
 |
 |
 |
Date :
2012-02-19 18:03:10 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบพระคุณท่านทั้งสองมากน่ะครับที่ให้ความรู้กับผม ได้ความรู็เพิ่มมาอีกหนึ่ง
|
 |
 |
 |
 |
Date :
2012-02-19 18:15:23 |
By :
auikung |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|