Esempio n. 1
0
function read_from_cache($table)
{
    $db_data = get_last_data($table);
    $servername = "mysql4.000webhost.com";
    $username = "******";
    $password = "******";
    $dbname = "a2124875_cache";
    $conn = new mysqli($servername, $username, $password, $dbname);
    $sql = " SELECT * FROM " . $table . "  WHERE data like '" . $db_data . "'";
    $name = array();
    $owner = array();
    $image_owner = array();
    $image_api = array();
    $desc = array();
    $prices = array();
    $links = array();
    if ($result = $conn->query($sql)) {
        while ($row = $result->fetch_row()) {
            array_push($name, urldecode($row[1]));
            array_push($owner, urldecode($row[2]));
            array_push($image_owner, urldecode($row[3]));
            array_push($image_api, urldecode($row[4]));
            array_push($desc, urldecode($row[5]));
            array_push($prices, urldecode($row[6]));
            array_push($links, urldecode($row[7]));
        }
        /* free result set */
        $result->close();
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }
    $conn->close();
    $array = array("name" => $name, "owner" => $owner, "image_owner" => $image_owner, "image_api" => $image_api, "desc" => $desc, "prices" => $prices, "links" => $links);
    return $array;
}
Esempio n. 2
0
function get_count_days($table, $data)
{
    $db_data = get_last_data($table);
    $data1 = $db_data;
    $data2 = $data;
    $days = get_diff_between_two_date($data1, $data2);
    return $days;
}
Esempio n. 3
0
    }
    return $res_array;
}
function get_last_data($nodes, $type_mea)
{
    /* The user must specify the type of measurement that wants to query */
    $meas = array();
    foreach ($nodes as $node) {
        $node_id = $node['id'];
        $query = "SELECT * FROM meas WHERE node_id =" . $node_id . " and type_mea = " . $type_mea . " ORDER by id DESC LIMIT 1";
        $res = mysql_query($query);
        $row = mysql_fetch_array($res);
        $tmp_array = array("id" => $row[0], "node_id" => $row[1], "date" => $row[2], "mea" => $row[3], "type_mea" => $row[4]);
        array_push($meas, $tmp_array);
    }
    return $meas;
}
if (!isset($_GET['nodes']) && !isset($_GET['data'])) {
    echo "Action not specified";
}
$con = connect_db();
if (isset($_GET['nodes'])) {
    echo json_encode(get_nodes());
} else {
    if (isset($_GET['data'])) {
        $type_data = $_GET['data'];
        $nodes = get_nodes();
        $data = get_last_data($nodes, $type_data);
        echo json_encode($data);
    }
}