SHOW:
|
|
- or go back to the newest paste.
| 1 | <!DOCTYPE html> | |
| 2 | <html> | |
| 3 | <head> | |
| 4 | </head> | |
| 5 | <body> | |
| 6 | <div id="post-wrapper"> | |
| 7 | <?php include "post.php"; ?> | |
| 8 | </div> | |
| 9 | </body> | |
| 10 | </html> | |
| 11 | ||
| 12 | <script> | |
| 13 | $(document).ready(function (){
| |
| 14 | setInterval(function(){
| |
| 15 | $('#post-wrapper).load("post.php");
| |
| 16 | },2000); | |
| 17 | }); | |
| 18 | </script> | |
| 19 | ||
| 20 | ############# | |
| 21 | post.php | |
| 22 | <?php | |
| 23 | ||
| 24 | function getLikes($id_post) {
| |
| 25 | global $conn; // pass $conn to function as $conn is out of function scope | |
| 26 | $query = "SELECT * FROM users WHERE id_user IN (SELECT id_user FROM likes WHERE id_post='{$id_post}' LIMIT 4");
| |
| 27 | if ($result = $conn->query($query)) {
| |
| 28 | if ($result->num_rows) {
| |
| 29 | WHILE ($row = $result->fetch_assoc()) {
| |
| 30 | $rows[] = $row; | |
| 31 | } | |
| 32 | return $rows; | |
| 33 | } | |
| 34 | } | |
| 35 | return null; | |
| 36 | } | |
| 37 | ||
| 38 | // your query | |
| 39 | WHILE ($row = $result->fetch_assoc()) {
| |
| 40 | $rows[] = $row; | |
| 41 | } | |
| 42 | ?> | |
| 43 | <?php foreach ($rows as $row): ?> | |
| 44 | <div class="post" id="<?= $row['postid']; ?>"> | |
| 45 | <div class="content"> | |
| 46 | <div class="content-image"><?= $row['postimage']; ?></div> | |
| 47 | <div class="content-text"><?= $row['content']; ?></div> | |
| 48 | </div> | |
| 49 | <div class="likes"> | |
| 50 | <?php if($likes = getLikes($row['id_post'])) {
| |
| 51 | echo '<ul>'; | |
| 52 | for ($i = 1; $i <= 3; $i++) {
| |
| 53 | // your logic | |
| 54 | } | |
| 55 | echo '</ul>'; | |
| 56 | } | |
| 57 | ?> | |
| 58 | </div> | |
| 59 | </div> | |
| 60 | <?php endforeach; ?> |