Php 改写为丹麦时间/日期
您好,这是我如何建立自己的论坛,但这是我必须如何“设置”到数据库中的日期,这是2012年5月30日应该看到的,但当它从数据库中取出时也应该看到的。我在MySQLI中这样构建它 下面是我在数据库中找到它时的外观Php 改写为丹麦时间/日期,php,sql,mysqli,Php,Sql,Mysqli,您好,这是我如何建立自己的论坛,但这是我必须如何“设置”到数据库中的日期,这是2012年5月30日应该看到的,但当它从数据库中取出时也应该看到的。我在MySQLI中这样构建它 下面是我在数据库中找到它时的外观 <form action="#" method="post" name="formular" onsubmit="return validerform ()"> <?php if ($stmt = $mysqli->p
<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
}
}
?>
头衔
:
下面是我将其从数据库中取出时的外观
<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;?>
不会有错误,但我只需要将其构建到丹麦日期中。为什么不在检索查询中使用mysql的日期格式函数?()
我只是复制你写的东西?试试这个查询,看看它是否符合你的要求。您的唯一更改是将日期格式(dato,“%d-%m-%Y”)改为dato而不是dato。下面是我试着复制它之后的样子不,空格是错的。它应该是
“%d-%m-%Y”
,没有空格。您还应该添加'as dato',这样您就可以通过名称获取值…它继续执行我之前在链接上显示的操作,该显示仍然与以前一样:(