-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinal_user_details.php
77 lines (60 loc) · 2.23 KB
/
final_user_details.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
<?php
// Connection parameters
$host = 'cspp53001.cs.uchicago.edu';
$username = 'meyer7';
$password = '37Mt4bwu11';
$database = $username.'DB';
// Attempting to connect
$dbcon = mysqli_connect($host, $username, $password, $database)
or die('Could not connect: ' . mysqli_connect_error());
// Selecting a database
// Unnecessary in this case because we have already selected
// the right database with the connect statement.
mysqli_select_db($dbcon, $database)
or die('Could not select database');
$user = $_GET["user"];
$current_user = $_GET["current_user"];
$query = "SELECT handle, name, email, accountCreate, following, followers FROM users WHERE handle='$user'";
$result = mysqli_query($dbcon, $query) or die ('user deets fail'.mysqli_error(dbcon));
$deets = mysqli_fetch_row($result);
$query = "SELECT text, sendTime FROM users, sends, tweets WHERE users.userID = sends.userID AND sends.tweetID = tweets.tweetID AND users.handle = '$user' ORDER BY sendTime DESC LIMIT 3";
$result = mysqli_query($dbcon, $query)
or die('Describe user failed: ' . mysqli_error($dbcon));
$json = array();
while ($tuple = mysqli_fetch_row($result)){
array_push($json, $tuple);
}
// Free result
mysqli_free_result($result);
$query = "SELECT * from users A, users B, follows WHERE A.handle = '$current_user' AND A.userID = followeeID AND B.userID = followerID AND B.handle = '$user'";
$result = mysqli_query($dbcon, $query) or die ('Follow lookup failed: '. mysqli_error($dbcon));
if ($result->num_rows == 1)
{
$follows = true;
}
else
{
$follows = false;
}
mysqli_free_result($result);
$query = "SELECT * from users A, users B, follows WHERE A.handle = '$current_user' AND A.userID = followerID AND B.userID = followeeID AND B.handle = '$user'";
$result = mysqli_query($dbcon, $query) or die ('Follow lookup failed: '. mysqli_error());
if ($result->num_rows == 1)
{
$following = true;
}
else
{
$following = false;
}
mysqli_free_result($result);
// Closing connection
mysqli_close($dbcon);
$finalJson = array (
"details" => $deets,
"tweets" => $json,
"follows" => $follows,
"following" => $following
);
echo json_encode($finalJson);
?>