Advertisement
michaelyuen

Untitled

May 11th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.88 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. if ($likerResult->num_rows > 0) {
  23.     $likerId = $likerFirstName = $likerPic = array();
  24.     $l = 0;
  25.  
  26.     while ($likerRow = $likerResult->fetch_assoc()) {
  27.                 echo '<ul class="friends-harmonic">';
  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="<?php echo $likerPic[$l]; ?>" alt="<?php echo $likerFirstName[$l]; ?>">
  45.                                     </a>
  46.                             </li>';
  47.                         $l++;
  48.         if ($l > 5) {
  49.             break;
  50.         }
  51.                 echo '<div class="names-people-likes">'.$likerName.'</div>';
  52.                 echo '</ul>';
  53.     }
  54. }
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement