2012-10-12 28 views
0

當圖像上傳到網站時,我想顯示它在圖片下上傳的月份。我在數據庫中有一個時間戳字段。如果可能的話,我可以從時間戳中得到月份嗎?我該怎麼做?

如果可能的話,我可以從時間戳中得到月份嗎?我該怎麼做?

我嘗試使用此代碼

<?php $query="SELECT * FROM magimgdes ORDER BY id DESC, time DESC " ; 

    $result=mysql_query($query) OR DIE(mysql_error()); 
    while($row=mysql_fetch_array($result)){ 
     $value1=$row['image']; 
     $value3=$row['time']; 
    ?> 
    <img src="admin/upload/hompageimage/<?php echo $value1; ?>" width="180" height="195" alt="magimage" /> 

<?php echo $value3;} ?></div> 

「時間」字段是在數據庫中的時間戳字段來做到這一點。

我只想回顯月份。

+2

數據庫中的「時間戳」字段不明確。什麼是列類型?或者你指的是UNIX時間戳? – nickb

+0

我編輯了問題 – piumi

+0

print'$ row ['time']'看起來像什麼? – Baba

回答

1

,你可以得到由date()

$weekday = date('N', $timestamp); 
$month = date('m', $timestamp); 
$day = date('d', $timestamp); 
0

首先,你需要到MySQL日期時間格式轉換爲UNIX時間戳,要做到這一點,你可以使用strtotime功能。然後你可以使用很多函數來處理該月份的提取,例如getdate函數。

$timestamp = strtotime($row['time']); // Convert to unix time. 
$info = getdate($timestamp); // Get the fields of a date (in an array). 
$month = $info['mon']; // This is the element that contains the month. 
echo $month; // This will print a number from 1 to 12. 
相關問題