0

您好,这就是我建立自己的论坛的方式,但这就是我必须将“设置”日期放入数据库中的方式,这应该是 30-5-2012 的样子,但是当将其从数据库中拉出时,它应该如何查看。我在 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&#230;se mere</a></td>
            <td>Dato: <?php echo $dato;?></td>
            </tr>
            <?php
                }
                }
            else
                {
                ?>
                    <p>der er ingen overhovedet!.. hmm</p>
                <?php
                }
            }
            ?>

在这里我像这样建立它必须转换为丹麦时间。

<?php echo $dato;?>

不会有错误,但我只需要将它构建到丹麦日期中。

4

1 回答 1

0

为什么不在检索查询中使用 mysql 的 date_format 函数?(php文档

SELECT id_forum, title, tekst, date_format(dato,'%d-%m-%Y') as dato, id_brugere 
FROM `forum` 
ORDER BY  `forum` . `id_forum` DESC LIMIT 0 , 30
于 2012-06-03T15:13:28.463 回答