Advertisement
michaelyuen

Untitled

May 11th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.85 KB | None | 0 0
  1. <?php
  2. $sql2       = "SELECT * FROM likes WHERE id_post='$row[id_post]'";
  3. $result2    = $conn->query($sql2);
  4. $totalLikes = (int) $result2->num_rows;
  5. ?>
  6. <span><?php echo $totalLikes; ?></span>
  7.                       <!--          </a> -->
  8. <?php
  9.  
  10. if ($row['type'] == 'friend') {
  11.     $sql3 = "SELECT * FROM friends_comments WHERE id_post='$row[id_post]'";
  12. } else {
  13.     $sql3 = "SELECT * FROM comments WHERE id_post='$row[id_post]'";
  14. }
  15.  
  16. $result3  = $conn->query($sql3);
  17. $totalComments = (int) $result3->num_rows;
  18.  
  19. //Displaying Liker's Profile Image and First Name
  20. $liker       = "SELECT * FROM users WHERE id_user IN (SELECT id_user FROM likes WHERE id_post='$row[id_post]')";
  21. $likerResult = $conn->query($liker);
  22. echo '<ul>'; // move to here
  23. if ($likerResult->num_rows > 0) {
  24.     $likerId = $likerFirstName = $likerPic = array();
  25.     $l = 0;
  26.  
  27.     while ($likerRow = $likerResult->fetch_assoc()) {
  28.         $likerId[] = $likerRow['id_user'];
  29.         $likerFirstName[] = $likerRow['firstName'];
  30.         $likerPic[] = $likerRow['profilePic'];
  31.         $likerTotal = $totalLikes - 2;
  32.         if ($l == 0) {
  33.             $likerName = "";
  34.         } else if ($l == 1) {
  35.             $likerName = $likerFirstName[0] . " liked this.";
  36.         } else if ($l <= 3) {
  37.             $likerName = $likerFirstName[0] . ", " . $likerFirstName[1] . " liked this.";
  38.         } else {
  39.             $likerName = $likerFirstName[0] . ", " . $likerFirstName[1] . " and " . $likerTotal . " more liked this.";
  40.         }
  41.                  
  42.                 echo '<li>
  43.                                 <a href="profile.php?id=<?php echo $likerId[$l]; ?>">
  44.                                         <img src="'.$likerPic[$l].'" alt="'.$likerFirstName[$l].'">
  45.                                     </a>
  46.                             </li>';
  47.                         $l++;
  48.         if ($l > 5) {
  49.             break;
  50.         }
  51.     }
  52.         echo '<li><div class="names-people-likes">'.$likerName.'</div></li>';
  53. }
  54. echo '</ul>';
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement