|
 |
|
ใส่ฟังชั่น ให้แล้วแต่ทำไมวันที่ไม่เป็นเป็นภาษาไทย อ่าค่ะ ต้องใส่เพิ่มตรงไหนอีกหรือเปล่าค่ะ ช่วยดูโค้ดให้หน่อยค่ะ |
|
 |
|
|
 |
 |
|
Code (PHP)
<?php
function DateThai($strDate)
{
$strYear = date("Y",strtotime($strDate))+543;
$strMonth= date("n",strtotime($strDate));
$strDay= date("j",strtotime($strDate));
$strMonthCut = Array("","ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
$strMonthThai=$strMonthCut[$strMonth];
return "$strDay $strMonthThai $strYear";
}
$strDate = "2008-08-14 ";
?><?
include ("ConnectActivity.php");
mysql_query ("SET NAMES utf8") or die (mysql_errno());
$strSQL = "SELECT * FROM activity ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
$Per_Page = 4; // Per Page
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$strSQL .=" order by id_activity ASC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
?>
<table width='100%' border='1' style='border-collapse: collapse'
bordercolor='#00F' bgcolor='#C6EAF0' >
<tr align='center'>
<td><b>รูปภาพกิจกรรม</b></td>
<td><b>หัวข้อกิจกรรม</b></td>
<td><b>วัน/เดือน/ปี</b></td>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
$date_activity = DateThai($row["date_activity"]);
?>
<tr>
<td align="center"><img src="<?=$objResult["pic_activity"];?>" width='100' height='100'alt=""></td>
<td><A HREF="ShowActivity1.php?id_activity=<?=$objResult[id_activity]?>"><?=$objResult["head_activity"];?> </A></td>
<td><?=$objResult["date_activity"];?></td>
</tr>
<?
}
?>
</table>
<br>
Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
<?
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";
}
mysql_close();
?>
<br />
Tag : PHP, MySQL, CakePHP

|
|
 |
 |
 |
 |
Date :
2012-02-23 13:03:07 |
By :
น้องอาโป |
View :
1025 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$row["date_activity"] // ต้องใช้รูปแบบเป็น yyyy-mm-dd เท่านั้นน่ะครับ
|
 |
 |
 |
 |
Date :
2012-02-23 13:18:47 |
By :
mangkunzo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ในหน้า html ใส่
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
รึเปล่าคะ
|
 |
 |
 |
 |
Date :
2012-02-23 13:20:23 |
By :
teukkead |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทดสอบ Code ข้างล่างนี้แล้ว มันออกไทยนะครับ
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
function DateThai($strDate)
{
$strYear = date("Y",strtotime($strDate))+543;
$strMonth= date("n",strtotime($strDate));
$strDay= date("j",strtotime($strDate));
$strMonthCut = Array("","ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
$strMonthThai=$strMonthCut[$strMonth];
return "$strDay $strMonthThai $strYear";
}
$test_date = "2008-08-14 ";
echo DateThai($test_date);
แปลได้อย่างเดียวว่า
$row["date_activity"] ไม่ตรงกับรูปแบบที่กำหนด
เหมือนกับที่คุณ mangkunzo บอกแหละครับ
ลอง echo $row["date_activity"] ดูว่ามันอยู่ในรูปแบบไหน นะครับ
|
 |
 |
 |
 |
Date :
2012-02-23 16:06:47 |
By :
13eachz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดูแล้วน่าจะผิดบรรทัดตรงนี้นะค่ะ
เพราะว่ามันไม่ได้ดึงฟังชั่น DateThai มาใช้
แต่ไม่รู้ว่าจะต้องดึงยังไง
Code (PHP)
<td><?=$objResult["date_activity"];?></td>
|
 |
 |
 |
 |
Date :
2012-02-23 20:55:58 |
By :
น้องอาโป |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|