<div class='column-updates'> <h2>Updates</h2><br><br> <?php for ($i = 0; $i < count($book_ids); $i++) { $query = "SELECT * FROM book_updates WHERE book_id='{$book_ids['0']}'"; $result = $connection->query($query); if (!$result) { die($connection->error); } $rows = $result->num_rows; for ($j = 0; $j < $rows; ++$j) { $result->data_seek($j); $row = $result->fetch_array(MYSQLI_ASSOC); $pages = $row['read_pages']; $time_ago = time_dif($row['added'], $now); echo "<div class='update-box'>"; echo "{$time_ago}:<br>{$username} read {$pages} pages of {$book_titles[$i]}."; echo "</div>"; } } function time_dif($latest, $now) { $last_seen = new DateTime($latest); $interval = $last_seen->diff($now); if ($interval->days == 0) { if ($interval->h != 0) { return $interval->h . ($interval->h == 1 ? " hour ago" : " hours ago"); } elseif ($interval->i > 10) { return $interval->i . " minutes ago"; } else {
$result = $connection->query($query); if (!$result) { die($connection->error); } $rows = $result->num_rows; for ($j = 0; $j < $rows; ++$j) { $result->data_seek($j); $row = $result->fetch_array(MYSQLI_ASSOC); if ($j % 2 == 0) { echo "<tr class='even'>"; } else { echo '<tr>'; } echo '<td>' . $row['username'] . '</td>'; echo '<td>' . time_dif($row['created'], $now) . '</td>'; echo '<td>' . time_dif($row['last_seen'], $now) . '</td>'; echo "<td><a class='stnd-button' href='movie_list.php?user_id="; echo $row['user_id'] . "'>Movie list</a></td></tr>"; } function time_dif($latest, $now) { $last_seen = new DateTime($latest); $interval = $last_seen->diff($now); if ($interval->days == 0) { if ($interval->h != 0) { return $interval->h . ($interval->h == 1 ? " hour ago" : " hours ago"); } elseif ($interval->i > 10) { return $interval->i . " minutes ago"; } else { return "Just now"; }