我正在一个显示来自 mySQL 数据库的日期的网站上工作。我目前在数据库中有这些列:id
, title
, date_start
, date_stop
, time_start
, time_stop
, image
, 和hyperlink
.
我希望date_start
并date_end
显示为 12 月 24 日,而不是 2012-12-24。
我目前的代码是这样的:
<html>
<style>
html{
font-family: arial;
}
</style>
<h1>Local Events</h1>
<?php
//mysql connection
mysql_connect('localhost', 'root', '') OR DIE ("Unable to connect to database! Please try again later.");
//selecting the table
mysql_select_db('local');
//query
$query = mysql_query("SELECT * FROM events3 WHERE date_end >= CURDATE() ORDER BY date_start LIMIT 5;");
//http://stackoverflow.com/questions/2597098/get-the-last-n-rows-in-the-database-in-order
//SELECT * FROM events ORDER BY date_start DESC LIMIT 5 ::Works but still need to reverse order
//SELECT * FROM events ORDER BY id DESC LIMIT 5;
//SELECT * FROM events ORDER BY id DESC LIMIT 5;
//WHERE year = '2012'
//fetch results
WHILE($rows= mysql_fetch_array($query)):
$id = $rows['id'];
$title = $rows['title'];
$date_start = $rows['date_start'];
$date_end = $rows['date_end'];
$time_start = $rows['time_start'];
$time_end = $rows['time_end'];
$location = $rows['location'];
$description = $rows['description'];
$image = $rows['image'];
$hyperlink = $rows['hyperlink'];
?>
<?php
//ID/ Title Display
echo "<b>ID:</b> "; echo "$id<br>";
echo "<b>Title:</b> "; echo "$title<br>";
//Date Display
echo "<b>Date Start:</b> ";
echo "$date_start"; echo ' - '; echo "$date_end<br>";
//Time Display
echo "<b>Time Frame:</b> ";
echo date('g:i a',strtotime($time_start)); echo" - "; echo date('g:i a',strtotime($time_end)); echo"<br>";
// echo "$time_start"; echo " - "; echo "$time_end<br>";
echo "<b>Location:</b> "; echo "$location<br>";
echo "<b>Description:</b> "; echo "$description<br><br><br>";
endwhile;
// SELECT * FROM events ORDER BY id DESC LIMIT 10;
?>
</html>
该代码使网站看起来像:
ID: 8
Title: Christmas
Date Start: 2012-12-44 - 2012-12-25
Time Frame: 9:00 am - 1:00 pm
Location: Everywhere
Description: Test event
我希望日期开始区域为 12 月 24 日至 25 日。我该怎么做?