|
 |
|
รบกวนเรื่องดึงวันที่จากฐานข้อมูลหน่อยค่ะ พอดีว่าต้องการดึงวันที่จากฐานข้อมูลมาแสดงในหน้าเว็บค่ะ |
|
 |
|
|
 |
 |
|
ใช้ substr แยกตัวเลขออกมาเป็นกลุ่ม แล้วแปลงค่าเป็นรูปแบบตามที่ต้องการ
แล้วค่อยแสดงอีกที
|
 |
 |
 |
 |
Date :
2009-10-08 14:22:27 |
By :
monotakari |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็ดึงปกตินะครับ เพียงแต่ก่อนที่จะแสดงผลให้ใช้ function นี้น่ะครับ
<?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";
}
$strDate = "2008-08-14 13:42:44";
echo "ThaiCreate.Com Time now : ".DateThai($strDate);
?>
|
 |
 |
 |
 |
Date :
2009-10-08 14:25:52 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณค่ะ 
|
 |
 |
 |
 |
Date :
2009-10-08 14:30:02 |
By :
Nicorobin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$date="2009-8-10";
list($year,$day,$month) =split("-",$date);
$list_m= array("มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
$month = $list_m[$month-1];
if(strlen($day)==1) $day="0".$day;
$year=$year+543;
echo "$day $month $year<br/>";
|
 |
 |
 |
 |
Date :
2009-10-08 14:30:22 |
By :
xbeginner01 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พี่ ๆ ค่ะทำไมมันถึงเป็น 1 ม.ค. 2513 แทนที่จะเป็น 8 ต.ค. 2552
โค๊ดค่ะ
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";
}
$strDate = "posttime";
echo .DateThai($strDate);
|
 |
 |
 |
 |
Date :
2009-10-08 15:15:16 |
By :
Nicorobin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอง
echo $strDate;
ออกมาดูครับ ว่าค่าที่น้องส่งเข้าไปในฟังก์ชั่น มีค่าเป็นอะไร
|
 |
 |
 |
 |
Date :
2009-10-08 15:18:12 |
By :
NanoThoro |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
posttime อ่ะค่ะ เป็นตัวแปรที่ส่งมาจากฐานข้อมูลค่ะ
ผิดถูกยังไงช่วยชึ้นแนะด้วยนะค่ะ
|
 |
 |
 |
 |
Date :
2009-10-08 15:23:04 |
By :
Nicorobin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผิดมหันเลย
$strDate = "posttime";
นี่มันเป็น ข้อความเฉยๆจ้า
|
 |
 |
 |
 |
Date :
2009-10-08 15:30:37 |
By :
NanoThoro |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$strDate = "2009-10-09";
echo DateThai($strDate);
ลองแบบนี้ก่อนได้ไหม
|
 |
 |
 |
 |
Date :
2009-10-08 15:31:48 |
By :
NanoThoro |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำตามที่พี่บอกแล้วขึ้นอ่ะค่ะ 8 ต.ค. 2552
แล้วเราจะดึงวันที่จากฐานข้อมูลขึ้นมายังไงอ่ะค่ะพี่
|
 |
 |
 |
 |
Date :
2009-10-08 15:35:08 |
By :
Nicorobin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอดูคำสั่งที่ดึงข้อมูลมาจากฐานข้อมูลหน่อยสิครับ
|
 |
 |
 |
 |
Date :
2009-10-08 15:36:19 |
By :
NanoThoro |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$strSQL = "SELECT * FROM News order by id DESC LIMIT 1";
|
 |
 |
 |
 |
Date :
2009-10-08 15:38:33 |
By :
Nicorobin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อีก สี่ห้าบันทัดที่ต่อจากบันทัดนี่ด้วยครับ
รบกวนชื่อฟิวด์ข้อมูลที่เก็บด้วยก็ดี
|
 |
 |
 |
 |
Date :
2009-10-08 15:40:24 |
By :
NanoThoro |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?
include "dbconletter.php";
$path="http://adminapac.asiapacific.co.th/asiapacific/Upload/img/";
$strSQL = "SELECT * FROM News order by id DESC LIMIT 1";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
$objQuery = mysql_query($strSQL);
while($row = mysql_fetch_array($objQuery,MYSQL_ASSOC))
{
?>
<div>
<p><b><? echo $row["posttime"];?> </b> <img src=<?= $path.$row["pictures"]?> border ="1" width=95 height=105><br>
<font size = 2 color= "#0066FF"> <br><b><?=$row["topices"]?> </b><img src="images/New_icons_07.gif" width="25" height="9" /><br></font>
<?php echo substr ($row ["detail"],0,150); ?>
<a href="viewnews.php?&id=<?=$row["id"]?> "target="<?php echo $row['id']; ?>">Read more...</a></p>
ฐานข้อมูลมีฟิลด์
id int
topices varchar
detail text
typenews varchar
view smallint(6)
posttime date
picture varchar
|
 |
 |
 |
 |
Date :
2009-10-08 15:46:40 |
By :
Nicorobin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไปไหนแล้ว
|
 |
 |
 |
 |
Date :
2009-10-08 15:47:01 |
By :
NanoThoro |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$strDate = $row["posttime"];
นี่เลยครับ
|
 |
 |
 |
 |
Date :
2009-10-08 15:48:37 |
By :
NanoThoro |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อยู่ค่ะ
|
 |
 |
 |
 |
Date :
2009-10-08 15:48:45 |
By :
Nicorobin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ว้าว
ได้แล้วค่ะ ขอบคุณพี่นาโนมากมายค่ะ
ลูกศิษย์ขอคาราวะ 
|
 |
 |
 |
 |
Date :
2009-10-08 15:50:41 |
By :
Nicorobin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
   
ม่ายพรือ ภาษาใต้
บ่เป็นหยัง ภาษาอิสาน
ภาษาบ้านเราก็ ไม่เป็นไรครับ
  
|
 |
 |
 |
 |
Date :
2009-10-08 15:53:54 |
By :
NanoThoro |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|