First of all, I am very new to C # and Json.
I wanted to plot a graph from mysql table data in a C # GUI. I made a PHP file to select data from the mysql database table and repeated the selected content in the json array using echo json_encode(array("result"=>$result))
here is my php:
<?php define('HOST','*********************'); define('USER','*********************'); define('PASS','*********************'); define('DB','***********************'); if($_SERVER['REQUEST_METHOD']=='GET'){ $start = $_GET['start']; $ending = $_GET['ending']; } $con = mysqli_connect(HOST,USER,PASS,DB); $sql = "SELECT * FROM table WHERE date_time BETWEEN '$start' and '$ending'" ; $res = mysqli_query($con,$sql); $result = array(); while($row = mysqli_fetch_array($res)){ array_push($result,array('id'=>$row[0],'p_pairs'=>$row[1],'temp1'=>$row[2] ,'temp2'=>$row[3],'temp3'=>$row[4],'temp4'=>$row[5],'temp5'=>$row[6],'avg_current'=>$row[7],'avg_voltage'=>$row[8],'kw'=>$row[9],'kwh'=>$row[10])); } echo json_encode(array($result)); mysqli_close($con); ?>
using the link, I can clearly see the json array between the datetime space. All I wanted to do was plot the temperature values (temp1, temp2, ..), p-pairs and others with date_date to view historical data.
All I get when I access a PHP page:
[[{"id":"1","p_pairs":"0000-00-00 00:00:00","temp1":"2","temp2":"100","temp3":"100","temp4":"100","temp5":"100","avg_current":"100","avg_voltage":"300","kw":"300","kwh":"300"},{"id":"2","p_pairs":"0000-00-00 00:00:00","temp1":"45","temp2":"105","temp3":"230","temp4":"100","temp5":"2500","avg_current":"570","avg_voltage":"100","kw":"250","kwh":"1000"},{"id":"3","p_pairs":"2016-01-07 21:10:00","temp1":"45","temp2":"105","temp3":"230","temp4":"100","temp5":"2500","avg_current":"570","avg_voltage":"100","kw":"250","kwh":"1000"},{"id":"4","p_pairs":"2016-01-07 21:10:00","temp1":"45","temp2":"105","temp3":"230","temp4":"100","temp5":"2500","avg_current":"570","avg_voltage":"100","kw":"250","kwh":"1000"}]]
NOTE. For some time, datetime is set here by default. I just wanted to show this array. The correct option would be ideal for plotting.
I can take this array in a string using a web request from C #. using the following code:
System.Net.WebClient wc = new System.Net.WebClient(); byte[] raw = wc.DownloadData("url to php"); string webData = System.Text.Encoding.UTF8.GetString(raw);
It will be a big help. If someone can help me build this in a line graph like date_time Vs temp1, temp2 or p_pairs and so on in a C # GUI ...
This will be a big help for me. Thank you in advance.