Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- </head>
- <body>
- <div id="post-wrapper">
- <?php include "post.php"; ?>
- </div>
- </body>
- </html>
- <script>
- $(document).ready(function (){
- setInterval(function(){
- $('#post-wrapper).load("post.php");
- },2000);
- });
- </script>
- #############
- post.php
- <?php
- function getLikes($id_post) {
- global $conn; // pass $conn to function as $conn is out of function scope
- $query = "SELECT * FROM users WHERE id_user IN (SELECT id_user FROM likes WHERE id_post='{$id_post}' LIMIT 4");
- if ($result = $conn->query($query)) {
- if ($result->num_rows) {
- WHILE ($row = $result->fetch_assoc()) {
- $rows[] = $row;
- }
- return $rows;
- }
- }
- return null;
- }
- // your query
- WHILE ($row = $result->fetch_assoc()) {
- $rows[] = $row;
- }
- ?>
- <?php foreach ($rows as $row): ?>
- <div class="post" id="<?= $row['postid']; ?>">
- <div class="content">
- <div class="content-image"><?= $row['postimage']; ?></div>
- <div class="content-text"><?= $row['content']; ?></div>
- </div>
- <div class="likes">
- <?php if($likes = getLikes($row['id_post'])) {
- echo '<ul>';
- for ($i = 1; $i <= 3; $i++) {
- // your logic
- }
- echo '</ul>';
- }
- ?>
- </div>
- </div>
- <?php endforeach; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement