我在数据库中有一个数据类型“TIMESTAMP”。我通过使用 html 中的“datetime-local”属性来传递该值。
<input type="datetime-local" id="start_time" class="form-control" name="start_time"/>
这工作正常,我可以将日期和时间上传到数据库。但是当我检索数据表单数据库进行编辑时,它不起作用。
PHP 代码
$query="SELECT * FROM hire WHERE hire_id='$id'";
$query_run=mysqli_query($con,$query);
$row=mysqli_fetch_array($query_run);
HTML 代码
<input type="datetime-local" value="<?php echo $row['start_time']; ?>" />
上面的 html 中的 php 没有显示任何结果。这里出了什么问题?
最佳答案
因为您将输入类型设置为“datetime-local”。您必须将日期设置为正确的格式才能使其显示在输入中。
将 start_time 值更改为这种格式。
$date = date("Y-m-d\TH:i:s", strtotime($row['start_time']));
然后在您的输入字段中回显 $date
<input type="datetime-local" value="<?php echo $date; ?>" />
关于php - 从 php 获取数据到 datetime-local,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34569007/