我知道如何为CSS显示日期:
.date {
float:left;
position:relative;
margin-right:10px;
padding:45px 5px 0;
}
.date .month{
text-transform:uppercase;
font-size:25px;
}
.date .day{
font-size:35px;
line-height:45px;
position:absolute;
left:5px;top:0;
}
.date .year{
display:block;
position:absolute;
right:-5px;
top:15px;
-webkit-transform:rotate(-90deg);
-moz-transform:rotate(-90deg);
-ms-transform:rotate(-90deg);
-o-transform:rotate(-90deg)
}
最终看起来像这样,在PHP的输出上:http://puu.sh/1uqZ2
和我现在一样,设置了我的CMS(新闻系统),但是如何让它看起来像那个图像中显示的时间戳呢?我是否必须为每行设置每个标记,例如$ day $ month $ year?
这是我目前的“addarticle.php”页面:
<?php
$submit = $_POST['submit'];
$remove = $_POST['remove'];
$news_content = $_POST['newscontent'];
$news_title = mysql_real_escape_string($_POST['newstitle']);
$news_author = mysql_real_escape_string($_POST['newsauthor']);
$news_date = date("l, F jS Y");
if ($submit)
{
$namecheck = mysql_query("SELECT news_title FROM articles WHERE news_title='$news_title'");
$count = mysql_num_rows($namecheck);
if ($count!=0)
{
die ('<div class="red" style="margin-bottom: 0;">Article <strong>'.$news_title.'</strong> already exists!</div>
<meta http-equiv="REFRESH" content="2;url=index">
');
}
if ($news_title&&$news_content&&$news_author)
{
$query = mysql_query("
INSERT INTO articles VALUES ('','$news_title','$news_content','$news_date','$news_author')
");
echo "<div class='green'>You have posted <strong>$news_title</strong> !</div>";
}else {
echo '<div class="red">You must fill in all fields!</div>';
}
}
?>
<form action="" method="POST">
Article Title :
<br />
<input name="newstitle" type="text" class="userpass" />
<br /><br />
Article Author :
<br />
<input name="newsauthor" type="text" class="userpass" value="<?php echo $_SESSION['username'] ?>" />
<br /><br />
Article Content :
<br />
<textarea id="elm1" name="newscontent" rows="7" cols="30" style="width: 100%"> </textarea>
<br />
<input name="submit" type="submit" class="button" value="Post News" />
<a href="viewarticle"><input name="edit" type="button" class="button" value="Edit Article" /></a>
</form>
答案 0 :(得分:1)
我假设有一个包含文章日期的数据变量$date
。与样式表结合使用时,以下代码应输出日期,如示例所示。
$day = date('d', $date);
$month = date('m', $date);
$year = date('Y', $date);
echo '<div class="date">'
. '<span class="month"' . $month . '</span>'
. '<span class="day">' . $day . '</span>'
. '<span class="year">' . $year . '</span>'
. '</div>';
我的代码与SQL无关,并假设您已经拥有该文章的日期。为了更好的答案,您应该删除所有不必要的代码,并为我们提供一个最小的例子。
我在代码中找不到从数据库中获取日期的部分。通常,您的数据库中有一个id
列,它是您的主键。如果是这样,您可以使用此SQL查询获取文章的日期。
SELECT news_date FROM articles WHERE id = ...