就像标题说的那样,我怎样才能使用这个日期函数将它保存为一个字符串,或者我以后可以把它从数据库中取出来?
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$newsTitel = $_POST['title'];
$submitDate = date('Y-m-d g:i:s A');
$newsContent = $_POST['newstext'];
mysql_query("INSERT INTO $tbl_name (Nieuwstitel, Nieuwsbericht, Postdatum)
VALUES('$newsTitel', '$newsContent', '$submitDate' ) ");
echo "Het bericht is successvol geplaatst!";
echo date('Y-m-d g:i:s A');
这会显示日期之类的新闻:2012 仅当它必须是完整长度时:
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$result = mysql_query("SELECT * FROM $tbl_name ORDER BY newsid DESC");
$count = mysql_num_rows($result);
while($row = mysql_fetch_array($result)){
$count = mysql_num_rows($result);
echo "<table class='newsList'>";
echo "<tr><div id='nav'><th align='left'>".$row['Nieuwstitel']."</th>
<th class='right'>".$row['Postdatum']."</div></tr>";
echo "<tr><td colspan='2'>".$row['Nieuwsbericht']."<br/></td></tr>";
echo "</table>";
if ($count == 0){
echo "<center><p>No news at the moment!</p><p> </p></center>";
}
}
}