Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require 'functions.php';
- //setting header to json
- header('Content-Type: application/json');
- //database
- define('DB_HOST', '127.0.0.1');
- define('DB_USERNAME', 'root');
- define('DB_PASSWORD', '');
- define('DB_NAME', 'binax');
- //get connection
- $mysqli = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);
- if(!$mysqli){
- die("Connection failed: " . $mysqli->error);
- }
- //query to get data from the table
- $query = "SELECT DATE_FORMAT(timeof, '%d-%m-%Y') AS giorno, FORMAT(SUM(totsell-cost),2) AS somma FROM POSITION WHERE DATE_FORMAT(timeof, '%d-%m') GROUP BY giorno ORDER BY timeof ASC";
- //execute query
- $result = $mysqli->query($query);
- //loop through the returned data
- $data = array();
- foreach ($result as $row) {
- $data[] = $row;
- }
- //free memory associated with result
- $result->close();
- //close connection
- $mysqli->close();
- //now print the data
- print json_encode($data);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement