こんにちは、これは私が自分のフォーラムを構築している方法ですが、これはデータベースに日付を「設定」する必要がある方法であり、2012 年 5 月 30 日のように見えるはずですが、データベースから引き出すときにどのように見えるべきかです。MySQLIでこのように構築します
データベースに配置したときの外観は次のとおりです
<form action="#" method="post" name="formular" onsubmit="return validerform ()">
<?php
if ($stmt = $mysqli->prepare('INSERT INTO `forum` (`title`, `tekst`, `dato`, `id_brugere`) VALUES (?, ?, ?, ?)')) {
$stmt->bind_param('ssss', $title, $tekst, $dato, $id_brugere);
//fra input ting ting..
$title = $_POST["title"];
$tekst = $_POST["tekst"];
$id_brugere = $_SESSION["user_id"];
$dato = date('d-m-Y');
$stmt->execute();
$stmt->close();
//er der fejl i tilgangen til table..
} else {
echo 'Der opstod en fejl i erklæringen: ' . $mysqli->error;
}
?>
<table border="0">
<tr>
<td id="tb-w_a"><p>Title</p></td>
<td>:</td>
<td><input type="text" name="title"></td>
</tr>
</table>
<textarea name="tekst" style="width:716px; height:170px;"></textarea><br />
<input type="submit" value="Opret indhold">
</form>
データベースから取り出すとこんな感じ
<?php
if ($stmt = $mysqli->prepare('SELECT id_forum, title, tekst, dato, id_brugere FROM `forum` ORDER BY `forum`.`id_forum` DESC LIMIT 0 , 30'))
{
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($id_forum, $title, $tekst, $dato, $id_brugere);
$count_res = $stmt->num_rows;
if($count_res > 0)
{
while ($stmt->fetch()) {
?>
<tr class="forumtoppen">
<td class="titleforum"><?php echo $title;?> - <a href="">Læse mere</a></td>
<td>Dato: <?php echo $dato;?></td>
</tr>
<?php
}
}
else
{
?>
<p>der er ingen overhovedet!.. hmm</p>
<?php
}
}
?>
このように作成した場所では、デンマーク時間に変換する必要があります。
<?php echo $dato;?>
エラーはありませんが、デンマークの日付に組み込む必要があります。