-
Notifications
You must be signed in to change notification settings - Fork 0
/
show_matches.php
61 lines (52 loc) · 1.29 KB
/
show_matches.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
<?php
require 'db.php';
session_start();
$params = json_decode(file_get_contents('php://input'));
$username = $_SESSION['username'];
// retrieve all rows with username as liker
$stmt = $mysqli->prepare("SELECT liker, liked FROM likes WHERE liker =?");
if(!$stmt){
echo json_encode(array(
"success" => false,
"message" => "Query Prep Failed"
));
exit;
}
$stmt->bind_param('s', $username);
$stmt->execute();
$likes = $stmt->get_result();
$stmt->close();
// retrieve all rows with username as liked
$stmt = $mysqli->prepare("SELECT liker, liked FROM likes WHERE liked =?");
if(!$stmt){
echo json_encode(array(
"success" => false,
"message" => "Query Prep Failed"
));
exit;
}
$stmt->bind_param('s', $username);
$stmt->execute();
$liked = $stmt->get_result();
$stmt->close();
$matches_send = array();
$liked_rows = array();
$liker_rows = array();
// check for matches
while($row_likes = mysqli_fetch_assoc($likes)){
$liked_rows[] = $row_likes['liked'];
}
while($row_liked = mysqli_fetch_assoc($liked)){
$liker_rows[] = $row_liked['liker'];
}
for ($i = 0; $i < sizeof($liked_rows); $i++){
if (in_array($liked_rows[$i], $liker_rows)){
$matches_send[] = $liked_rows[$i];
}
}
// send json of matches
echo json_encode(array(
"success" => true,
"matches" => $matches_send
));
?>