-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetwishes.php
41 lines (35 loc) · 1.42 KB
/
getwishes.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
<?php
include ("mysqliconnect.php");
$useIP = $_SERVER['REMOTE_ADDR'];
//get wishes
//$getwishesquery = "SELECT * FROM wishes WHERE flag=0 ORDER BY time DESC LIMIT 120";
if($_GET['t'] == "archived"){
$getwishesquery = "SELECT wish, offer, country FROM wishes order by time DESC";
} else {
$page = $_GET['page'];
if($page > 0){
$offset = $page * 100;
} else {
$offset = 0;
}
$getwishesquery = "SELECT wishes.time, wishes.ip_address, wishes.wish, wishes.offer, wishes.country, wishes.X, wishes.Y, wishes.wishid, wishes.token, wishes.email, totalstars.c, istar.s, wishes.flag from wishes left join (select wishid, count(*) as c from wish_stars group by wishid) AS totalstars on wishes.wishid = totalstars.wishid left join (select wishid, count(*) as s from wish_stars where ip_address = '".$useIP."' group by wishid) AS istar on wishes.wishid=istar.wishid where flag=0 order by wishes.time DESC limit ".$offset.", 100";
}
$res = $mysqli->query($getwishesquery);
$outjson = array();
$wishes = array();
$res->data_seek(0);
while ($row = $res->fetch_assoc()) {
$wish = array();
$wish["wish"] = $row["wish"];
$wish["offer"] = $row["offer"];
$wish["country"] = $row["country"];
$wish["x"] = $row["X"];
$wish["y"] = $row["Y"];
$wish["id"] = $row["wishid"];
$wish["stars"] = $row["c"];
$wish["istar"] = $row["s"];
$wishes[] = $wish;
}
$outjson["wishes"] = $wishes;
echo json_encode($outjson);
?>