-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyour_stats.php
106 lines (51 loc) · 3.12 KB
/
your_stats.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
<div class="container"> <!-- -fluid makes the table full width,,padding ect to get side space -->
<div class="row">
<div class="col-xs-12"></div>
<table class="table table-striped table-bordered table-hover" id="example" cellspacing="0" > <!--, table table-inverse-->
<thead >
<tr >
<th>Name</th>
<th>Company</th>
<th>Total Firsts Ever</th>
<th>Total For Year</th>
<th>Firsts Made This Month</th>
<th>Firsts Made last 7 days</th>
<th>Firsts Made Today</th>
</tr>
</thead>
<tbody >
<?php
// troulle is no entry for user without a value..select statement is joining wrong so user not displayed unless they have a value.
$result = mysqli_query($conn,"SELECT id, name, surname from users where id = '".$_SESSION['usr_id']."'
");
while($firsts=mysqli_fetch_assoc($result)){
{
echo "<tr>";
//changes date to english format from a time stamp
// echo"<td>".$firsts['usr_id']."</td>";
//echo"<td>".$firsts['company_id']."</td>";
//totoal firsts ever
echo"<td>".$firsts['name']. ' '.$firsts['surname']."</td>";
$result = mysqli_query($conn,"SELECT f.usr_id, u.id, u.name , u.surname,c.company_name, c.company_id, count(f.usr_id) as num_rows from firsts f left outer join users u on u.id = f.usr_id left join company c on u.company_id = c.company_id group by f.usr_id having f.usr_id ='".$_SESSION['usr_id']."'
");
while($firsts=mysqli_fetch_assoc($result)){
echo"<td>".$firsts['company_name']."</td>";
echo"<td>".$firsts['num_rows']."</td>";
//total firsts ever
$result = mysqli_query($conn,"SELECT count(date_made) as total_ever FROM firsts where year(curdate()) = year(date_made) and usr_id= '".$_SESSION['usr_id']."'");
while($firsts=mysqli_fetch_assoc($result)){
echo"<td>".$firsts['total_ever']."</td>";
//total this cal_days_in_month(calendar, month, year) month(curdate()) = month(date_made)
$result = mysqli_query($conn,"SELECT count(date_made) as this_month FROM firsts WHERE MONTH(date_made) = MONTH(curdate()) AND YEAR(date_made) = YEAR(CURRENT_DATE()) and usr_id='".$_SESSION['usr_id']."' ");
while($firsts=mysqli_fetch_assoc($result)){
echo"<td>".$firsts['this_month']."</td>";
$result = mysqli_query($conn,"SELECT count(date_made) as last7_days FROM `firsts` WHERE DATE(`date_made`) BETWEEN CURDATE() - INTERVAL 7 DAY AND CURDATE() and usr_id='".$_SESSION['usr_id']."' ");
while($firsts=mysqli_fetch_assoc($result)){
echo"<td>".$firsts['last7_days']."</td>";
$result = mysqli_query($conn,"SELECT count(date_made) as made_today FROM `firsts` WHERE DATE(`date_made`) = CURDATE() and usr_id='".$_SESSION['usr_id']."' ");
while($firsts=mysqli_fetch_assoc($result)){
echo"<td>".$firsts['made_today']."</td>";
}}}}}}}
?>
</tbody>
</table>