-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopular.php
51 lines (41 loc) · 1.46 KB
/
popular.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<div class="alert bg-white pop">
<b>Popular Posts/Authors</b><hr>
<?php
$popular_sql=mysqli_query($conn,"SELECT post_id FROM like_data");
$a="";
while ($popular=mysqli_fetch_assoc($popular_sql))
{
$a.=$popular['post_id'].',';
}
$b=substr($a, 0,-1);
$c=explode(",", $b);
$d=array_count_values($c);
arsort($d);
$e=array_keys($d);
$f=array_slice($e, 0,3); //to set the room of the array
foreach ($f as $key => $value)
{
$pop_sql=mysqli_query($conn,"SELECT post.*,user.name,user.photo FROM post INNER JOIN user ON post.user_id=user.id WHERE post.id='$value'");
$pop=mysqli_fetch_assoc($pop_sql)
?>
<div class="media border mb-2">
<a href="" class="card-link text-dark">
<div class="media-left">
<?php
if ($pop['post_photo'])
{ ?>
<img src="img/<?php echo $pop['post_photo']?>" class="media-object my-2 ml-2" width="120px">
<?php }
?>
</div>
<div class="media-body ml-2">
<h6 class="media-heading mt-3"><?php echo $pop['title']?></h6>
<small><?php echo substr($pop['description'], 0,100) ?></small></a><br>
<a href="" class="text-dark"><small>Posted by : <b><?php echo $pop['name']?></b></small>
<img src="img/4.png" class="rounded-circle float-right mr-2 mb-1" width="30px" height="30px">
</a>
</div>
</div>
<?php }
?>
</div>