วันพุธที่ 7 กันยายน พ.ศ. 2554
การใช้ For ตัวแปรมากกว่า 1 ตัว
<?php
if($_GET['sv'] != 1 &&$_GET['sv'] == "" ){
echo "<center> แก้ไขข้อความ กรุณาจัดบรรทัดให้ไกล้เคียงตำแหน่งเดิมนะครับ </center> <br>";
} else {
require_once("nbbc.php");
$texts = new BBCode;
$text1 = $texts->Parse($row_rsNews['comments']);
$shows = explode("<br />" , $text1);
$txtcount = count(explode("<br />" , $text1));
for($i=0&$m=165;$i<$txtcount&$m<$txtcount+165;$i++&$m++){ //for ใช้ตัวแปรมากกว่า 1 ตัว
echo $m." data = ".$shows[$i]."<br>";
}}
?>
if($_GET['sv'] != 1 &&$_GET['sv'] == "" ){
echo "<center> แก้ไขข้อความ กรุณาจัดบรรทัดให้ไกล้เคียงตำแหน่งเดิมนะครับ </center> <br>";
} else {
require_once("nbbc.php");
$texts = new BBCode;
$text1 = $texts->Parse($row_rsNews['comments']);
$shows = explode("<br />" , $text1);
$txtcount = count(explode("<br />" , $text1));
for($i=0&$m=165;$i<$txtcount&$m<$txtcount+165;$i++&$m++){ //for ใช้ตัวแปรมากกว่า 1 ตัว
echo $m." data = ".$shows[$i]."<br>";
}}
?>
วันจันทร์ที่ 5 กันยายน พ.ศ. 2554
MYSQL กรองข้อมูลรายชั่วโมง-นาที + เลือกข้อมูลย้อนหลังไป 30 วัน
1.ข้อมูลเดิม แสดงทุก 15 นาที
SELECT
rawdata_t.TimeTag_DT,
rawdata_t.Device_ID,
rawdata_t.Reading_FL
FROM
rawdata_t
WHERE
rawdata_t.Device_ID = 7 AND
DATE_FORMAT(rawdata_t.TimeTag_DT, '%Y-%m-%d') BETWEEN DATE_ADD(curdate(), interval -30 DAY) AND CURDATE() #แสดงข้อมูล ย้อนหลังไป 30 วัน
ORDER BY
rawdata_t.TimeTag_DT DESC
2. เปลี่ยนให้แสดงทุกชั่วโมง
SELECT
rawdata_t.TimeTag_DT,
rawdata_t.Device_ID,
rawdata_t.Reading_FL
FROM
rawdata_t
WHERE
rawdata_t.Device_ID = 7 AND
DATE_FORMAT(rawdata_t.TimeTag_DT, '%Y-%m-%d') BETWEEN DATE_ADD(curdate(), interval -30 DAY) AND CURDATE()
GROUP BY
DATE(rawdata_t.TimeTag_DT), HOUR(rawdata_t.TimeTag_DT) #แสดงข้อมูลรายวันและทุก ๆ ชั่วโมง
ORDER BY
rawdata_t.TimeTag_DT DESC
3. แสดงข้อมูลทุก 30 นาที
SELECT
rawdata_t.TimeTag_DT,
rawdata_t.Device_ID,
rawdata_t.Reading_FL
FROM
rawdata_t
WHERE
rawdata_t.Device_ID = 7 AND
DATE_FORMAT(rawdata_t.TimeTag_DT, '%Y-%m-%d') BETWEEN DATE_ADD(curdate(), interval -30 DAY) AND CURDATE()
GROUP BY
DATE(rawdata_t.TimeTag_DT), HOUR(rawdata_t.TimeTag_DT), FLOOR(MINUTE(rawdata_t.TimeTag_DT)/30) #แสดงข้อมูลทุก 30 นาที
ORDER BY
rawdata_t.TimeTag_DT DESC
วันศุกร์ที่ 2 กันยายน พ.ศ. 2554
HTTP Headers รวมตัวอย่าง Headers ของ php
HTTP Headers รวมตัวอย่าง Headers ของ php
// See related links for more status codes
// Use this header instruction to fix 404 headers
// produced by url rewriting...
header('HTTP/1.1 200 OK');
// Page was not found:
header('HTTP/1.1 404 Not Found');
// Access forbidden:
header('HTTP/1.1 403 Forbidden');
// The page moved permanently should be used for
// all redrictions, because search engines know
// what's going on and can easily update their urls.
header('HTTP/1.1 301 Moved Permanently');
// Server error
header('HTTP/1.1 500 Internal Server Error');
// Redirect to a new location:
header('Location: http://www.example.org/');
// Redriect with a delay:
header('Refresh: 10; url=http://www.example.org/');
print 'You will be redirected in 10 seconds';
// you can also use the HTML syntax:
// <meta http-equiv="refresh" content="10;http://www.example.org/ />
// override X-Powered-By value
header('X-Powered-By: PHP/4.4.0');
header('X-Powered-By: Brain/0.6b');
// content language (en = English)
header('Content-language: en');
// last modified (good for caching)
$time = time() - 60; // or filemtime($fn), etc
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
// header for telling the browser that the content
// did not get changed
header('HTTP/1.1 304 Not Modified');
// set content length (good for caching):
header('Content-Length: 1234');
// Headers for an download:
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.zip"');
header('Content-Transfer-Encoding: binary');
// load the file to send:
readfile('example.zip');
// Disable caching of the current document:
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Pragma: no-cache');
// set content type:
header('Content-Type: text/html; charset=iso-8859-1');
header('Content-Type: text/html; charset=utf-8');
header('Content-Type: text/plain'); // plain text file
header('Content-Type: image/jpeg'); // JPG picture
header('Content-Type: application/zip'); // ZIP file
header('Content-Type: application/pdf'); // PDF file
header('Content-Type: audio/mpeg'); // Audio MPEG (MP3,...) file
header('Content-Type: application/x-shockwave-flash'); // Flash animation
header('content-type:text/xml'); //php ส่ง Head เป็น XML
// show sign in box
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');
print 'Text that will be displayed if the user hits cancel or ';
print 'enters wrong login data';
การสลับสีระหว่าง ROW Javascipt + สั่งตัวกระพริบ
<style type="text/css">
/* class สำหรับแถวส่วนหัวของตาราง */
.tr_head{
background-color:#333333;
color:#FFFFFF;
}
/* class สำหรับแถวแรกของรายละเอียด */
.tr_odd{
background-color:#F8F8F8;
}
/* class สำหรับแถวสองของรายละเอียด */
.tr_even{
background-color:#F2F2F2;
}
</style>
/* class สำหรับแถวส่วนหัวของตาราง */
.tr_head{
background-color:#333333;
color:#FFFFFF;
}
/* class สำหรับแถวแรกของรายละเอียด */
.tr_odd{
background-color:#F8F8F8;
}
/* class สำหรับแถวสองของรายละเอียด */
.tr_even{
background-color:#F2F2F2;
}
</style>
2.
<table id="mytable" width="50%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Name</td>
<td>Age</td>
<td>Sex</td>
</tr>
<tr>
<td>Mike</td>
<td>15</td>
<td>male</td>
</tr>
<tr>
<td>Linda</td>
<td>20</td>
<td>female</td>
</tr>
<tr>
<td>Joe</td>
<td>14</td>
<td>male</td>
</tr>
<tr>
<td>Greg</td>
<td>32</td>
<td>male</td>
</tr>
</table>
<tr>
<td>Name</td>
<td>Age</td>
<td>Sex</td>
</tr>
<tr>
<td>Mike</td>
<td>15</td>
<td>male</td>
</tr>
<tr>
<td>Linda</td>
<td>20</td>
<td>female</td>
</tr>
<tr>
<td>Joe</td>
<td>14</td>
<td>male</td>
</tr>
<tr>
<td>Greg</td>
<td>32</td>
<td>male</td>
</tr>
</table>
<table id="mytable" width="50%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Name</td>
<td>Age</td>
<td>Sex</td>
</tr>
<tr>
<td>Mike</td>
<td>15</td>
<td>male</td>
</tr>
<tr>
<td>Linda</td>
<td>20</td>
<td>female</td>
</tr>
<tr>
<td>Joe</td>
<td>14</td>
<td>male</td>
</tr>
<tr>
<td>Greg</td>
<td>32</td>
<td>male</td>
</tr>
</table>
<tr>
<td>Name</td>
<td>Age</td>
<td>Sex</td>
</tr>
<tr>
<td>Mike</td>
<td>15</td>
<td>male</td>
</tr>
<tr>
<td>Linda</td>
<td>20</td>
<td>female</td>
</tr>
<tr>
<td>Joe</td>
<td>14</td>
<td>male</td>
</tr>
<tr>
<td>Greg</td>
<td>32</td>
<td>male</td>
</tr>
</table>
3.
<script language="javascript">
window.onload = function clr() {
var a=document.getElementById('mytable'); // อ้างอิงตารางด้วยตัวแปร a
for(i=0;i<a.rows.length;i++){ // วน Loop นับจำนวนแถวในตาราง
if(i>0){ // ตรวจสอบถ้าไม่ใช่แถวหัวข้อ
if(i%2==1){ // ตรวจสอบถ้าไม่ใช่แถวรายละเอียด
a.rows[i].className="tr_odd"; // กำหนด class แถวแรก
}else{
a.rows[i].className="tr_even"; // กำหนด class แถวที่สอง
}
}else{ // ถ้าเป็นแถวหัวข้อกำหนด class
a.rows[i].className="tr_head";
}
}
}
</script>
window.onload = function clr() {
var a=document.getElementById('mytable'); // อ้างอิงตารางด้วยตัวแปร a
for(i=0;i<a.rows.length;i++){ // วน Loop นับจำนวนแถวในตาราง
if(i>0){ // ตรวจสอบถ้าไม่ใช่แถวหัวข้อ
if(i%2==1){ // ตรวจสอบถ้าไม่ใช่แถวรายละเอียด
a.rows[i].className="tr_odd"; // กำหนด class แถวแรก
}else{
a.rows[i].className="tr_even"; // กำหนด class แถวที่สอง
}
}else{ // ถ้าเป็นแถวหัวข้อกำหนด class
a.rows[i].className="tr_head";
}
}
}
</script>
<!-- เริ่ม Script ตัวกระพริบ <blink> -->
<script type="text/javascript">
function blinkIt() {
if (!document.all) return;
else {
for(i=0;i<document.all.tags('blink').length;i++){
s=document.all.tags('blink')[i];
s.style.visibility=(s.style.visibility=='visible')?'hidden':'visible';
}
}
}
/// กรณีที่มี มี Java ใน Window Onload แล้ว เรียก script 2 ตัวพร้อมกัน
<body onload="clr();setInterval('blinkIt()',1000)">
วันพุธที่ 31 สิงหาคม พ.ศ. 2554
การสร้าง Flash chart ด้วย Anychart แบบติดต่อฐานข้อมูล
ใช้ไฟล์อยุ่ 2 ไฟล์ในการแสดงผลคือ
1.
1. สำหรับแสดงผล Anychart
name : aychart.htm
<!-- saved from url=(0014)about:internet -->
<html xmlns="http://www.w3.org/1999/xhtml" ><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../AnyChart/styles/style.css" rel="stylesheet" type="text/css"></link>
<link href="../AnyChart/styles/style.css" rel="stylesheet" type="text/css"></link>
<script type="text/javascript" language="JavaScript" src="../AnyChart/js/AnyChart.js"></script>
<script type="text/javascript" language="JavaScript" src=".../AnyChart/anychart/gallery/GalleryItem.js"></script>
<title>ปริมาณน้ำไหลเ้ข้า-ระบายผ่านเครื่องและผ่าน Spillway รายวันเขื่อนสิริกิติ์ </title>
<script src="../AnyChart/anychart/gallery/Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</head>
<body topmargin="0">
<table align="center" vspace="0" hspace="0">
<tr valign="Center">
<td id="sample" height="100%" colspan="2" align="Center">
<script type="text/javascript">
AC_FL_RunContent( 'id','chart','name','chart','width','1000','height','600','codebase','http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab','pluginspage','http://www.adobe.com/go/getflashplayer','src','../AnyChart/swf/AnyChart','bgcolor','#FFFFFF','allowscriptaccess','always','flashvars','XMLFile=anydata.php','movie','../AnyChart/swf/AnyChart' ); //end AC code
</script><noscript>
<object id="chart"
name="chart"
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
width="1000"
height="600"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="../AnyChart/swf/AnyChart.swf" />
<param name="bgcolor" value="#FFFFFF" />
<param name="allowScriptAccess" value="always" />
<param name="flashvars" value="XMLFile=anydata.php" />
<embed type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer"
src="../AnyChart/swf/AnyChart.swf"
width="1000"
height="600"
id="chart"
name="chart"
bgColor="#FFFFFF"
allowScriptAccess="always"
flashvars="XMLFile=anydata.php" />
</object>
</noscript>
</body>
</html>
2. file anychart Setting และส่งออกเป็น Head type XML เพื่อให้ Anychart รู้จัก
name : anydata.php
<?php require_once('Connections/xxxx.php');
header('content-type:text/xml'); //ส่วนนี้สำคัญมากกำหนดให้ php ส่ง Head เป็น XML ให้ Anychart รู้จัก
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
header('content-type:text/xml'); //ส่วนนี้สำคัญมากกำหนดให้ php ส่ง Head เป็น XML ให้ Anychart รู้จัก
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_sk50, $sk50);
$query_rs_tu01 = "SELECT xxxxxx";
$rs_tu01 = mysql_query($query_rs_tu01, $sk50) or die(mysql_error());
$row_rs_tu01 = mysql_fetch_assoc($rs_tu01);
$totalRows_rs_tu01 = mysql_num_rows($rs_tu01);
$query_rs_tu01 = "SELECT xxxxxx";
$rs_tu01 = mysql_query($query_rs_tu01, $sk50) or die(mysql_error());
$row_rs_tu01 = mysql_fetch_assoc($rs_tu01);
$totalRows_rs_tu01 = mysql_num_rows($rs_tu01);
do {
$data0[] = $row_rs_tu01['dates'];
$data1[] = number_format($row_rs_tu01['inflows'],3);
$data2[] = number_format($row_rs_tu01['releases'],3);
$data3[] = number_format($row_rs_tu01['spillway'],3);
$data4[] = number_format($row_rs_tu01['tot_release'],3);
} while ($row_rs_tu01 = mysql_fetch_assoc($rs_tu01));
$data = '<data>';
$data .= "<series type = 'Area' name ='Inflow' color ='#00FF00'>";
for ($i = 0;$i<$totalRows_rs_tu01;$i++) {
$data .= '<point name="'.$data0[$i].'" y="'.$data1[$i].'" />';
}
$data .= '</series>';
$data .= "<series type = 'Area' name ='Release+Spillway' color ='#FF00FF'>";
for ($i = 0;$i<$totalRows_rs_tu01;$i++)
{
$data .= '<point name="'.$data0[$i].'" y="'.$data4[$i].'" />';
}
$data .= '</series>';
$data .= "<series type = 'Area' name ='Release' color ='#FFFF00'>";
for ($i = 0;$i<$totalRows_rs_tu01;$i++)
{
$data .= '<point name="'.$data0[$i].'" y="'.$data2[$i].'" />';
}
$data .= '</series>';
$data .= "<series type = 'Area' name ='Spillway' color ='#FF0000'>";
for ($i = 0;$i<$totalRows_rs_tu01;$i++) {
$data .= '<point name="'.$data0[$i].'" y="'.$data3[$i].'" />';
}
$data .= '</series>';
$data .= '</data>';
$data0[] = $row_rs_tu01['dates'];
$data1[] = number_format($row_rs_tu01['inflows'],3);
$data2[] = number_format($row_rs_tu01['releases'],3);
$data3[] = number_format($row_rs_tu01['spillway'],3);
$data4[] = number_format($row_rs_tu01['tot_release'],3);
} while ($row_rs_tu01 = mysql_fetch_assoc($rs_tu01));
$data = '<data>';
$data .= "<series type = 'Area' name ='Inflow' color ='#00FF00'>";
for ($i = 0;$i<$totalRows_rs_tu01;$i++) {
$data .= '<point name="'.$data0[$i].'" y="'.$data1[$i].'" />';
}
$data .= '</series>';
$data .= "<series type = 'Area' name ='Release+Spillway' color ='#FF00FF'>";
for ($i = 0;$i<$totalRows_rs_tu01;$i++)
{
$data .= '<point name="'.$data0[$i].'" y="'.$data4[$i].'" />';
}
$data .= '</series>';
$data .= "<series type = 'Area' name ='Release' color ='#FFFF00'>";
for ($i = 0;$i<$totalRows_rs_tu01;$i++)
{
$data .= '<point name="'.$data0[$i].'" y="'.$data2[$i].'" />';
}
$data .= '</series>';
$data .= "<series type = 'Area' name ='Spillway' color ='#FF0000'>";
for ($i = 0;$i<$totalRows_rs_tu01;$i++) {
$data .= '<point name="'.$data0[$i].'" y="'.$data3[$i].'" />';
}
$data .= '</series>';
$data .= '</data>';
?>
<anychart>
<settings>
<animation enabled="True"/>
</settings>
<charts>
<chart type="CategorizedVertical">
<chart_settings>
<title>
<text>ปริมาณน้ำไหลเ้ข้า-ระบายผ่านเครื่องและผ่าน Spillway รายวันเขื่อนสิริกิติ์ </text>
</title>
<scale minimum="1"/>
<legend enabled="true" ignore_auto_item="false" padding="5" align="Spread" position="top">
<template/>
<columns_separator enabled="false"/>
<background>
<inside_margin right="10" left="10"/>
</background>
<title enabled ="false" />
</legend>
<axes>
<x_axis tickmarks_placement="Center">
<labels display_mode="Rotated" rotation="90" align="inside" allow_overlap="true"/>
<zoom enabled="true" start="400" end="500"/>
<line enabled="true"/>
<title>
<text>date</text>
</title>
</x_axis>
<y_axis>
<scale minimum="0"/>
<labels>
<format>{%Value}{numDecimals:0}</format>
</labels>
<title>
<text>mcm.</text>
</title>
</y_axis>
</axes>
</chart_settings>
<data_plot_settings default_series_type="SplineArea">
<area_series>
<marker_settings enabled="True">
<marker type="Circle" size="4"/>
</marker_settings>
<tooltip_settings enabled="true">
<format>
<![CDATA[{%SeriesName}:{%Name}{enabled:false}={%Value}{numDecimals:2}mcm.]]>
</format>
<background>
<corners all="3" type="Rounded"/>
<effects enabled="false"/>
<border type="Solid" opacity="0.2" color="#FF0000"/>
</background>
</tooltip_settings>
<area_style>
<line enabled="true" color="DarkColor(%Color)"/>
<fill opacity="0.3" color="%Color"/>
<states>
<hover color="white"/>
</states>
</area_style>
</area_series>
</data_plot_settings>
<?php
<anychart>
<settings>
<animation enabled="True"/>
</settings>
<charts>
<chart type="CategorizedVertical">
<chart_settings>
<title>
<text>ปริมาณน้ำไหลเ้ข้า-ระบายผ่านเครื่องและผ่าน Spillway รายวันเขื่อนสิริกิติ์ </text>
</title>
<scale minimum="1"/>
<legend enabled="true" ignore_auto_item="false" padding="5" align="Spread" position="top">
<template/>
<columns_separator enabled="false"/>
<background>
<inside_margin right="10" left="10"/>
</background>
<title enabled ="false" />
</legend>
<axes>
<x_axis tickmarks_placement="Center">
<labels display_mode="Rotated" rotation="90" align="inside" allow_overlap="true"/>
<zoom enabled="true" start="400" end="500"/>
<line enabled="true"/>
<title>
<text>date</text>
</title>
</x_axis>
<y_axis>
<scale minimum="0"/>
<labels>
<format>{%Value}{numDecimals:0}</format>
</labels>
<title>
<text>mcm.</text>
</title>
</y_axis>
</axes>
</chart_settings>
<data_plot_settings default_series_type="SplineArea">
<area_series>
<marker_settings enabled="True">
<marker type="Circle" size="4"/>
</marker_settings>
<tooltip_settings enabled="true">
<format>
<![CDATA[{%SeriesName}:{%Name}{enabled:false}={%Value}{numDecimals:2}mcm.]]>
</format>
<background>
<corners all="3" type="Rounded"/>
<effects enabled="false"/>
<border type="Solid" opacity="0.2" color="#FF0000"/>
</background>
</tooltip_settings>
<area_style>
<line enabled="true" color="DarkColor(%Color)"/>
<fill opacity="0.3" color="%Color"/>
<states>
<hover color="white"/>
</states>
</area_style>
</area_series>
</data_plot_settings>
<?php
// Output data section
echo $data;
?>
</chart>
</charts>
</anychart>
<?php
mysql_free_result($rs_tu01);
?>
</charts>
</anychart>
<?php
mysql_free_result($rs_tu01);
?>
กำหนดวันที่ภาษาไทยให้กับ PHP วันที่แบบไทย
$thai_day_arr=array("อาทิตย์","จันทร์","อังคาร","พุธ","พฤหัสบดี","ศุกร์","เสาร์");
$thai_month_arr=array( "0"=>"", "1"=>"มกราคม", "2"=>"กุมภาพันธ์", "3"=>"มีนาคม", "4"=>"เมษายน", "5"=>"พฤษภาคม", "6"=>"มิถุนายน", "7"=>"กรกฎาคม", "8"=>"สิงหาคม", "9"=>"กันยายน", "10"=>"ตุลาคม", "11"=>"พฤศจิกายน", "12"=>"ธันวาคม" );
function thai_date($time){
global $thai_day_arr,$thai_month_arr;
$thai_date_return="วัน".$thai_day_arr[date("w",$time)]; $thai_date_return.= "ที่ ".date("j",$time); $thai_date_return.=" เดือน".$thai_month_arr[date("n",$time)];
$thai_date_return.= " พ.ศ.".(date("Yํ",$time)+543);
return $thai_date_return;
}
$eng=1224562026; กรณีเป็น timestamp $eng_date=time();
$ldate = date('Y-n-d',strtotime("-1 day")); // กำหนดให้แสดงเมื่อวาน date('Y-n-d',strtotime("-1 day") วันพรุ่งนี้ =date('Y-n-d',strtotime("+1 day") วันปัจจุบัน =date('Y-n-d') เท่านั้น
$eng_date= strtotime($ldate); //แปลงวันให้เป็นรูปแบบ Timestamp
echo thai_date($eng_date) //แสดงผล
// ถ้ามีการเก็บวันที่และเวลาในรูปแบบ timestamp // สามารถนำมาใช้งานในฟังก์ชันได้ดังนี้
// แสดงวันที่ปัจจุบัน echo thai_date($eng_date);
//การประยุกต์ใช้งาน
// ถ้ามีการเก็บวันที่และเวลาในรูปแบบ date // คือ 2008-10-31 ต้องเปลี่ยนเป็น timestamp
// ด้วยคำส่ง strtotime("2008-10-31");
// แสดงวันที่ 31 เดือน ตุลาคม ปี 2008 แบบภาษาไทย $eng_date=strtotime("2008-10-31"); echo thai_date($eng_date);
เพิ่มเติม
$thai_month_arr=array( "0"=>"", "1"=>"มกราคม", "2"=>"กุมภาพันธ์", "3"=>"มีนาคม", "4"=>"เมษายน", "5"=>"พฤษภาคม", "6"=>"มิถุนายน", "7"=>"กรกฎาคม", "8"=>"สิงหาคม", "9"=>"กันยายน", "10"=>"ตุลาคม", "11"=>"พฤศจิกายน", "12"=>"ธันวาคม" );
function thai_date($time){
global $thai_day_arr,$thai_month_arr;
$thai_date_return="วัน".$thai_day_arr[date("w",$time)]; $thai_date_return.= "ที่ ".date("j",$time); $thai_date_return.=" เดือน".$thai_month_arr[date("n",$time)];
$thai_date_return.= " พ.ศ.".(date("Yํ",$time)+543);
return $thai_date_return;
}
$eng=1224562026; กรณีเป็น timestamp $eng_date=time();
$ldate = date('Y-n-d',strtotime("-1 day")); // กำหนดให้แสดงเมื่อวาน date('Y-n-d',strtotime("-1 day") วันพรุ่งนี้ =date('Y-n-d',strtotime("+1 day") วันปัจจุบัน =date('Y-n-d') เท่านั้น
$eng_date= strtotime($ldate); //แปลงวันให้เป็นรูปแบบ Timestamp
echo thai_date($eng_date) //แสดงผล
// ถ้ามีการเก็บวันที่และเวลาในรูปแบบ timestamp // สามารถนำมาใช้งานในฟังก์ชันได้ดังนี้
// แสดงวันที่ปัจจุบัน echo thai_date($eng_date);
//การประยุกต์ใช้งาน
// ถ้ามีการเก็บวันที่และเวลาในรูปแบบ date // คือ 2008-10-31 ต้องเปลี่ยนเป็น timestamp
// ด้วยคำส่ง strtotime("2008-10-31");
// แสดงวันที่ 31 เดือน ตุลาคม ปี 2008 แบบภาษาไทย $eng_date=strtotime("2008-10-31"); echo thai_date($eng_date);
เพิ่มเติม
Find Yesterdays date
<?php
echo "yesterday was ".date("Y-m-d", strtotime("-1 days"));
?>
Output
yesterday was 2010-04-10
Find Date one week ago
<?php
echo "1 week form today was ".date("Y-m-d", strtotime("-1 weeks"));
?>
Output
1 week form today was 2010-04-04
Find Date one month after
<?php
echo "1 month from today will be ".date("Y-m-d", strtotime("+1 months"));
?>
Output
1 month form today will be 2010-05-11
สมัครสมาชิก:
บทความ (Atom)


