Advertisement
michaelyuen

Untitled

May 11th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.87 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.         echo '<ul class="friends-harmonic">';
  26.     while ($likerRow = $likerResult->fetch_assoc()) {
  27.         $likerId[] = $likerRow['id_user'];
  28.         $likerFirstName[] = $likerRow['firstName'];
  29.         $likerPic[] = $likerRow['profilePic'];
  30.         $likerTotal = $totalLikes - 2;
  31.         if ($l == 0) {
  32.             $likerName = "";
  33.         } else if ($l == 1) {
  34.             $likerName = $likerFirstName[0] . " liked this.";
  35.         } else if ($l <= 3) {
  36.             $likerName = $likerFirstName[0] . ", " . $likerFirstName[1] . " liked this.";
  37.         } else {
  38.             $likerName = $likerFirstName[0] . ", " . $likerFirstName[1] . " and " . $likerTotal . " more liked this.";
  39.         }
  40.                  
  41.                 echo '<li>
  42.                                 <a href="profile.php?id=<?php echo $likerId[$l]; ?>">
  43.                                         <img src="<?php echo $likerPic[$l]; ?>" alt="<?php echo $likerFirstName[$l]; ?>">
  44.                                     </a>
  45.                             </li>';
  46.                         $l++;
  47.         if ($l > 5) {
  48.             break;
  49.         }
  50.                 echo '<div class="names-people-likes">'.$likerName.'</div>';
  51.                 echo '</ul>';
  52.     }
  53. }
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement