我想以荷兰语格式输入MySQL中的日期。现在他给了我标准格式。我是否需要在输出列表或插入文件中更改它?
这是我的插入代码:
<?php
session_start();
include '../dbh.php';
$costname = $_POST['costname'];
$category = $_POST['category'];
$subcategory = $_POST['subcategory'];
$price = $_POST['price'];
$info = $_POST['info'];
$costdate = $_POST['costdate']->format("d-m-Y H:i:s");
$iduser = $_SESSION['id'];
if(empty($costname)) {
header("Location: ../dashboard.php?error=emptycostname");
exit();
}
if(empty($category)) {
header("Location: ../dashboard.php?error=emptycatergory");
exit();
}
if(empty($subcategory)) {
header("Location: ../dashboard.php?error=emptysubcatergory");
exit();
}
if(empty($price)) {
header("Location: ../dashboard.php?error=emptyprice");
exit();
}
if(empty($info)) {
header("Location: ../dashboard.php?error=emptyinfo");
exit();
}
else {
$sql = "INSERT INTO costs (costname, category, subcategory, price, info, userid, costdate)
VALUES ('$costname', '$category', '$subcategory', '$price', '$info', '$iduser', '$costdate')";
$result = mysqli_query($conn, $sql);
header("Location: ../dashboard.php");
}
现在我需要将它显示在列表中,我已经使用此代码从db:
获取它<?php
include('includes/sessionstart.php');
include 'dbh.php';
if (isset($_SESSION['id'])) { ?>
<?php include 'includes/header.php';
// costslist define mysql
$sql_costs = "SELECT * FROM costs WHERE userid='".$_SESSION['id']."'";
$result_costs = mysqli_query($conn, $sql_costs);
$costname = $row_costs['costname'];
<div class="content">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="header">
<h4 class="title">Wonen</h4>
<p class="category">Kosten gespendeerd aan uw woning.</p>
</div>
<div class="content table-responsive table-full-width">
<table class="table table-hover table-striped">
<thead>
<th>Subcategorie</th>
<th>Kostnaam</th>
<th>Kostprijs</th>
<th>Extra info</th>
<th>Datum toegevoegd</th>
</thead>
<tbody>
<?php
while($row = $result_costs->fetch_assoc()) { ?>
<tr>
<td><?php echo $row['subcategory']; ?></td>
<td><?php echo $row['costname']; ?></td>
<td><?php echo $row['price']; ?></td>
<td><?php echo $row['info']; ?></td>
<td><?php echo $row['costdate']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
答案 0 :(得分:1)
您可以使用MySQL的DATE_FORMAT
函数格式化它,无论您想要什么。以下是更新选择查询以对其进行格式化的方法:
$sql_costs = "SELECT *, DATE_FORMAT(costdate, '%d-%m-%Y %H:%i:%s') AS costdate FROM costs WHERE userid='".$_SESSION['id']."'";
在此处详细了解DATE_FORMAT
功能:
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format