-
Notifications
You must be signed in to change notification settings - Fork 1
/
sort_users.php
52 lines (40 loc) · 1.94 KB
/
sort_users.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
<?php
include('dbconfig.php');
session_start();
mysqli_query($conn, "CREATE TEMPORARY TABLE reward_pts SELECT * from userData;");
$self_ID = $_SESSION['id'];
//add reward points for hobbies
$fetch_hobbies = mysqli_query($conn, "SELECT hobbie_ID FROM `hobbieData` WHERE userID = $self_ID");
$hobbie_count = $fetch_hobbies->num_rows;
$hobbie_increment = round((37.5)/($hobbie_count), 3);
while($hobbie = $fetch_hobbies->fetch_assoc()){
$h_id = $hobbie['hobbie_ID'];
$fetch_h_users = mysqli_query($conn, "SELECT userID FROM `hobbieData` WHERE hobbie_ID = $h_id");
while($row = $fetch_h_users->fetch_assoc()){
$ptr_id = $row['userID'];
//increment hobbie_reward by 3 points for that userID
$fetch_h_rwd_pts = mysqli_query($conn, "SELECT rwd_pts from reward_pts where userID = $ptr_id");
$h_rwd_pts = $fetch_h_rwd_pts->fetch_assoc();
$h_rwd = floatval($h_rwd_pts['rwd_pts']);
$h_rwd += $hobbie_increment;
mysqli_query($conn, "UPDATE reward_pts SET rwd_pts = $h_rwd where userID = $ptr_id");
}
}
//add reward points for goals
$fetch_goals = mysqli_query($conn, "SELECT goal_ID FROM `goalData` WHERE userID = $self_ID");
$goal_count = $fetch_goals->num_rows;
$goal_increment = round((62.5)/($goal_count),3);
while($goal = $fetch_goals->fetch_assoc()){
$g_id = $goal['goal_ID'];
$fetch_h_users = mysqli_query($conn, "SELECT userID FROM `goalData` WHERE goal_ID = $g_id");
while($row = $fetch_h_users->fetch_assoc()){
$ptr_id = $row['userID'];
//increment goal_reward by 5 points for that userID
$fetch_g_rwd_pts = mysqli_query($conn, "SELECT rwd_pts from reward_pts where userID = $ptr_id");
$g_rwd_pts = $fetch_g_rwd_pts->fetch_assoc();
$g_rwd = floatval($g_rwd_pts['rwd_pts']);
$g_rwd += $goal_increment;
mysqli_query($conn, "UPDATE reward_pts SET rwd_pts = $g_rwd where userID = $ptr_id");
}
}
?>