function getSensorData($sensor, $conn)
{
    $sql = "SELECT * FROM `sensors` WHERE {$sensor} = 1";
    $result = $conn->query($sql);
    $json = array();
    if ($result->num_rows > 0) {
        // output data of each row
        while ($row = $result->fetch_assoc()) {
            $json = ["error" => 0, "id" => $row["id"], "lon" => $row["lon"], "lat" => $row["lat"], "waterlevel" => $row["waterlevel"], "lastDataTime" => $row["last data time"]];
            $encoded_json = json_encode($json);
            print_r($encoded_json);
        }
    } else {
        makeError(2);
        die;
    }
    $conn->close();
}
Exemple #2
0
        die(json_encode($rarr));
    } else {
        // not voted yet
        if ($vote != 0) {
            execQuery("insert into vts values ({$r['id']}, {$r['postid']}, {$vote})", 2);
            if ($vote == 1) {
                execQuery("update posts set weight=weight+1,upcount=upcount+1 where postid={$r['postid']}");
            } else {
                execQuery("update posts set weight=weight-1,downcount=downcount+1 where postid={$r['postid']}");
            }
        }
        die(json_encode($rarr));
    }
} else {
    // invalid option
    makeError(1);
}
function removeVote($id, $postid)
{
    $res = execQuery("delete from vts where id={$id} and postid={$postid}");
}
function genCountQuery($wt, $up, $dn)
{
    $str = '';
    if ($wt != 0) {
        $str .= "weight=weight" . prefixSign($wt) . ',';
    }
    if ($up != 0) {
        $str .= "upcount=upcount" . prefixSign($up) . ',';
    }
    if ($dn != 0) {
Exemple #3
0
                }
                // get posts for user
                $postObj->addSelection("{$gq} gid=1");
                $res = $postObj->getPostFeed($r['id']);
                $rarr['posts'] = array();
                while ($row = $res->fetch_assoc()) {
                    $rarr['posts'][] = $row;
                }
                die(json_encode($rarr));
            }
        } else {
            if ($r['action'] == 'comment') {
                // make a comment on a post
                // content, postid
                $comObj = new Comments($r);
                $comObj->checkTokenValid();
                $comObj->checkInputHas(['content', 'postid']);
                $comObj->addInsertsFromArray($r, ['id', 'content', 'postid']);
                $comObj->addInsert('username', getUsername($r['id']));
                $comObj->addInsert('doc', date('Y-m-d H:i:s'));
                $result = $comObj->insert();
                if ($result) {
                    execQuery("update posts set commentcount=commentcount+1 where postid={$r['postid']}");
                    die(json_encode($rarr));
                }
            } else {
                makeError(ERR_NOACTION);
            }
        }
    }
}
function execQuery($query, $error = 1)
{
    global $con;
    $result = mysqli_query($con, $query);
    if ($result) {
        return $result;
    } else {
        // echo $query;
        // echo mysqli_error($con);
        makeError($error);
    }
}