我在mysql中添加了一个datetime列。它将当前时间戳作为其值。 我在php中回应它时遇到错误。说这是一个未定义的索引。
$sql="SELECT `idea-content` FROM `ideas` ";
$result = mysqli_query($mysql_link, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "<li>
<div class='comment-main-level'>
<!-- Avatar -->
<div class='comment-avatar'><img src='#' alt=''></div>
<!-- Contenedor del Comentario -->
<div class='comment-box'>
<div class='comment-head'>
<h6 class='comment-name by-author'><a href='#''>Agustin Ortiz</a></h6>
<span>".$row['time']."</span>
<i class='fa fa-reply'></i>
<i class='fa fa-heart'></i>
</div>
<div class='comment-content'>".$row['idea-content']."
</div>
</div>
</div></li>";
}
答案 0 :(得分:2)
答案 1 :(得分:0)
您选择了1个字段,但尝试输出2个字段
您的选择中缺少time
字段,您也可以使用DATE_FORMAT
格式化日期
$sql="SELECT `idea-content`, DATE_FORMAT(`time`, '%W %M %Y') as `time` FROM `ideas` ";
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format