-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathauthor.php
129 lines (100 loc) · 4.93 KB
/
author.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php include 'header.php'; ?>
<div id="main-content">
<div class="container">
<div class="row">
<div class="col-md-8">
<!-- post-container -->
<div class="post-container">
<?php
include "admin/config.php";
if(isset($_GET['author_id'])){
$author_id = $_GET['author_id'];
$query_cat = "SELECT * FROM user WHERE user_id = {$author_id}";
$result_cat = mysqli_query($connection, $query_cat) or die("Query Failed.");
$row_new = mysqli_fetch_assoc($result_cat);
?>
<h2 class="page-heading"><?php echo strtoupper($row_new['username']); ?></h2>
<?php
$limit = 3;
if(isset($_GET['page'])){
$page_number = $_GET['page'];
}else{
$page_number = 1;
}
$offset = ($page_number - 1) * $limit;
$query = "SELECT post.post_id, post.title, post.description,post.post_img, post.post_date,post.category, category.category_name,user.username,post.author FROM post
LEFT JOIN category ON post.category = category.category_id
LEFT JOIN user ON post.author = user.user_id WHERE post.author={$author_id}
ORDER BY post.post_id DESC LIMIT {$offset },{$limit}";
$result = mysqli_query($connection,$query) or die("Failed");
$count = mysqli_num_rows($result);
if($count > 0){
while($row = mysqli_fetch_assoc($result)){
?>
<div class="post-content">
<div class="row">
<div class="col-md-4">
<a class="post-img" href="single.php?id=<?php echo $row['post_id'] ?>"><img src="admin/upload/<?php echo $row['post_img'] ?>" alt=""/></a>
</div>
<div class="col-md-8">
<div class="inner-content clearfix">
<h3><a href='single.php?id=<?php echo $row['post_id'] ?>'><?php echo $row['title'] ?></a></h3>
<div class="post-information">
<span>
<i class="fa fa-tags" aria-hidden="true"></i>
<a href='category.php?cid=<?php echo $row['category'] ?>'><?php echo $row['category_name'] ?></a>
</span>
<span>
<i class="fa fa-user" aria-hidden="true"></i>
<a href='author.php?author_id=<?php echo $row['author'] ?>'><?php echo $row['username'] ?></a>
</span>
<span>
<i class="fa fa-calendar" aria-hidden="true"></i>
<?php echo $row['post_date'] ?>
</span>
</div>
<p class="description">
<?php echo substr($row['description'], 0,170)."..." ?>
</p>
<a class='read-more pull-right' href='single.php?id=<?php echo $row['post_id'] ?>'>read more</a>
</div>
</div>
</div>
</div>
<?php }
}else{
echo "No Record Found.";
}
$query2 = "SELECT * FROM post WHERE post.author={$author_id}";
$result2 = mysqli_query($connection,$query2) or dir("Failed.");
if(mysqli_num_rows($result2)){
$total_records = mysqli_num_rows($result2);
$total_page = ceil($total_records/$limit);
echo "<ul class='pagination admin-pagination'>";
if($page_number > 1){
echo '<li><a href="author.php?author_id'.$author_id.'&page='.($page_number-1).'">prev</a></li>';
}
for($i = 1; $i <= $total_page; $i++){
if($i == $page_number){
$active = "active";
}else{
$active = "";
}
echo '<li class='.$active.'><a href="author.php?author_id='.$author_id.'&page='.$i.'">'.$i.'</a></li>';
}
if($total_page > $page_number){
echo '<li><a href="author.php?author_id='.$author_id.'&page='.($page_number+1).'">next</a></li>';
}
echo "</ul>";
}
}else{
echo "<h2>No Record Found.</h2>";
}
?>
</div><!-- /post-container -->
</div>
<?php include 'sidebar.php'; ?>
</div>
</div>
</div>
<?php include 'footer.php'; ?>