-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.php
124 lines (100 loc) · 3.63 KB
/
profile.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
<?php session_start();
require_once 'user_validation.php';
require_once 'common_functions.php';
if(!is_logged())
RedirectTo('index.php');
?>
<?php require_once 'header.php' ?>
<body>
<div class="brand">Best Friend Ever</div>
<div class="address-bar">Everything about dogs</div>
<?php include 'navigation.php' ?>
<?php
$num_comments = $num_articles = $email = $username = $nickname = $member_since = $num_articles = $num_comments = null;
if(is_logged()) {
$id = $_COOKIE['user_id'];
$conn = OpenDBconnection();
// retrieving personal info
$sql = " SELECT email, username, nickname, created_at FROM users WHERE id = '$id'";
$result = $conn->query($sql);
$usr_info = $result->fetch_assoc();
$email = $usr_info['email'];
$username = $usr_info['username'];
$nickname = $usr_info['nickname'];
$member_since = $usr_info['created_at'];
$result->free();
// retrieving number of articles and comments
$sql = " SELECT
(SELECT COUNT(*) FROM articles WHERE user_id = '$id') as articles,
(SELECT COUNT(*) FROM comments WHERE user_id = '$id') as comments; ";
$result = $conn->query($sql);
$data = $result->fetch_assoc();
$num_articles = $data['articles'];
$num_comments = $data['comments'];
$result->free();
echo "<!--Display Profile Data-->
<div class='container'>
<div class='row'>
<div class='box'>
<div class='col-lg-12'>
<hr>
<h2 class='intro-text text-center'>Welcome
<strong>$nickname</strong>
</h2>
<hr>
<h1> </h1>
<div class='col-lg-4'>
<h4>Personal info</h4>
<p><strong>Full name:	</strong>$username</p>
<p><strong>Nickname:	</strong>$nickname</p>
<p><strong>Email:	</strong>$email</p>
<br>
</div>
<div class='col-lg-4'>
<h4>Statistics</h4>
<p><strong>Joined:	</strong>$member_since</p>
<p><strong>Total number of articles:	</strong>$num_articles</p>
<p><strong>Total number of comments:	</strong>$num_comments</p>
<br>
</div>
</div>
</div>
</div>
<div class='row'>
<div class='box'>
<div class='col-lg-12'>
<hr>
<h2 class='intro-text text-center'>YOUR
<strong>articles</strong>
</h2>
<hr>
<div class=\"clearfix\"></div>
<div class='col-lg-12'>";
// user articles
$sql = " SELECT a.id, a.created_at, a.title, COUNT(c.article_id) as comments
FROM articles a
LEFT JOIN comments c ON a.id = c.article_id
WHERE a.user_id = '$id'
GROUP BY a.id
ORDER BY a.created_at DESC";
$result = $conn->query($sql);
// while there are rows to be fetched...
while ($list = $result->fetch_assoc()) {
echo "
<div class='col-lg-12'>
<p>".$list['created_at']." <strong>".$list['title']."</strong> - ".$list['comments']." ". pluralize($list['comments'], 'comment')."</pre>
</div>";
}
$result->free();
echo "</div>
</div>
</div>
</div>
</div>
<!-- /.container -->
";
}
?>
<?php include 'footer.html' ?>
<?php include 'Scripts.html' ?>
</body>