0

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

Chefk5
  • 456
  • 6
  • 14

2 Answers2

2

This code will get the date and time of your local machine (PC)

echo date("d-m-Y H:i:sa");

https://stackoverflow.com/a/43066760/3471640

Community
  • 1
  • 1
Hatami
  • 21
  • 2
  • 5
0

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

Musa
  • 96,336
  • 17
  • 118
  • 137