Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('Content-Type: application/json');
- //SQL-information
- $dbservername = "d0020e.noexit.tv";
- $dbusername = "d0020e_data";
- $dbpassword = "hidden";
- $dbname = "d0020e_data";
- //Create new mysql connection
- $conn = new mysqli($dbservername, $dbusername, $dbpassword, $dbname);
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- else
- {
- if(isset($_GET['n'])){
- if($_GET['n'] == all) {
- //Query all points
- $sql = "SELECT * FROM test_dp ORDER BY tstamp DESC";
- }
- else {
- //Query n number of points
- $limit = intval($_GET['n']);
- $sql = "SELECT * FROM test_dp ORDER BY tstamp DESC LIMIT $limit";
- }
- }
- else {
- //n is not set, query a default number of 360 points
- $limit = 360;
- $sql = "SELECT * FROM test_dp ORDER BY tstamp DESC LIMIT $limit";
- }
- $data_points = array();
- $result = $conn->query($sql);
- //Add all points to array and echo in JSON format
- while($row = $result->fetch_assoc())
- {
- $point = array("x" => $row['tstamp'] , "y" => $row['y']);
- array_push($data_points, $point);
- }
- echo json_encode($data_points, JSON_NUMERIC_CHECK);
- }
- $conn->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement