Hi. I am working on a newsfeed like similar to facebook. Where I compare the time when something happened in my mysql table to the current time and output: something something happened x min ago.
First i connect to mysql with this code:
$conn = db_connect();
$newsfeed = $conn->query("select info, username, time from newsfeed ORDER BY time DESC LIMIT 10");
if (!$newsfeed) {
//die(msg(0,"Could not execute query"));
}
I am new to mysql so im not sure of this is correct. I want the last 10 updates in the database to show up with the next functions with the latest updates above the others:
$newsfeed_info_array = $newsfeed->fetch_array(MYSQLI_NUM);
$newsfeed_info = $newsfeed_info_array[0];
$newsfeed_username = $newsfeed_info_array[1];
$newsfeed_time= $newsfeed_info_array[2];
$newsfeed_info_split = explode("-", $newsfeed_info); //type and info
date_default_timezone_set('Europe/Paris');
$current_time = strtotime("now");
if ($newsfeed_info_split[0] == "reg")
{
//The next line is the problem
$time_diff = date_diff($current_time, $newsfeed_time);
echo "<p>User $newsfeed_username just registerted ".date( "00:i:s", $newsfeed_time)." min ago</p><br>";
}
if ($newsfeed_info_split[0] == "xxx")
{
echo "blabla x min ago"
}