$app->get("/sessions/:id", function ($id) use($app) { $resp = array(); $req = $app->request(); // first retrieve the required session so we can // find the ip address $id = Database::sanitise($id); $sql = "SELECT id, ip FROM Logs where id='{$id}'"; $sessions = Database::queryToArray($sql); if (sizeof($sessions) == 0) { // invalid id $resp["error"] = "invalid id"; echo json_encode($resp); } else { // valid id $session = $sessions[0]; $ip = $session["ip"]; // get the rest of the logs for this session $sql = "SELECT id, datetime, breeders from Logs where ip='{$ip}' ORDER BY datetime ASC"; $sessions = Database::queryToArray($sql); $new_sess = array(); foreach ($sessions as $session) { // an array of synths $synths = json_decode($session["breeders"]); //print_r($synths); //$synths = SynthesizerHelper::removeBadsynths($synths); $new_sess[] = array("breeders" => $synths); } echo json_encode($new_sess); } }); $app->run();