I added a datetime column in mysql. It takes current timestamp as its value. I am facing an error when I echo it in php. Saying it is an undefined index.
$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>";
}
Table: https://ibb.co/eU9Jd5
This code will get the date and time of your local machine (PC)
echo date("d-m-Y H:i:sa");
You selected 1 field but try to output 2 fields.
The time
field is missing from your select, aslo you can use DATE_FORMAT
to format the out of the date
$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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.