I'm kind of stuck on this and would like some help. I have a MySQL table with the following information:
created | users | points |
---|---|---|
2018-08-01 13:00:00 | Anna | 85.00 |
2018-08-01 11:23:00 | alfred | 35.00 |
2018-08-01 17:04:00 | george | 125.00 |
2018-08-01 19:30:00 | pretty | 42.00 |
2018-08-01 08:35:00 | Alex | 76.00 |
2018-08-01 10:29:00 | John | 94.00 |
2018-08-01 15:27:00 | Hugo | 75.30 |
I want to get the difference in minutes between the current date and the start_session column for each row in an HTML table, so my code is as follows:
<table class="table">
<tr><td><b>Minutes</b></td><td><b>User - Points</b></td></tr>
<?php
$sql = "SELECT * FROM users";
$res = mysql_query($sql);
$date = date(Y-m-d H:i:s);
if(mysql_num_rows($res)>0){
while($row = mysql_fetch_array($res){
$start_session = $row['created'];
$start_date = new DateTime($start_session);
$since_start = $start_date->diff(new DateTime($date));
$minutes = $since_start->days * 24 * 60;
$minutes += $since_start->h * 60;
$minutes += $since_start->i;
?>
<tr>
<td>
<?php echo $minutes." min"; ?>
</td>
<td>
<?php echo $row['users']." - ".$row['points']." points"; ?>
</td>
</tr>
<?php
}
}
?>
</table>
So far it's working fine, but I need to refresh the page to update the number of minutes elapsed and I want this to be real time, I know AJAX can be an option along with SetInterval but I just want to update the minutes column and not rewrite the entire table with the information. How can I solve it?
I will appreciate your response.
you can mark
TD
it with the creation date in timeStamp format and then do the necessary calculations every N seconds with a javascript interval.a sample with static data: