jVectormap adding markers from database only adds one marker - php

I am trying to add markers from a MySQL database via PHP into jvectormap (version 2.0.2).
I'm not sure what I'm doing wrong but when I add the markers dynamically using .AddMarkers, only a single marker shows up, which is the last marker in the JSON response.
This is my code:
JavaScript:
$("#airportsmap").vectorMap({
map: "world_mill_en",
scaleColors: ["#eff0f1", "#eff0f1"],
normalizeFunction: "polynomial",
hoverOpacity: .7,
hoverColor: !1,
regionStyle: {
initial: {
fill: "#6673a7"
}
},
markerStyle: {
initial: {
stroke: "transparent"
},
hover: {
stroke: "rgba(112, 112, 112, 0.30)"
}
},
backgroundColor: "transparent",
markers:[]
});
function loadairportmarkers(){
$.ajax({
type: "POST",
url: "modules/getfavouriteairportsdash.php",
dataType: 'json',
cache: false,
success: function(response) {
if(!response.errors && response.result) {
$.each(response.result, function( index, value) {
addMapPoint(value[3], value[4], value[2]);
});
} else {
$.each(response.errors, function( index, value) {
$('input[name*='+index+']').addClass('error').after('<div class="errormessage">'+value+'</div>')
});
}
}
})
}
function addMapPoint(lat, lon, title){
var map = $('#airportsmap').vectorMap('get', 'mapObject');
map.addMarkers([{ latLng: [lat, lon], name: title }], []);
}
PHP
$stmt = $mysqli->prepare("
SELECT .... query here
");
$stmt->bind_param('is', $uid,$emp);
$stmt->execute();
$result = $stmt->get_result();
while($row = $result->fetch_all())
{
$returnResult = $row;
}
}
mysqli_close($mysqli);
echo json_encode(['result' => $returnResult, 'errors' => $errors]);
exit;
This results in the following JSON response:
{"result":[["HUEN","FAOR","Entebbe International Airport","0.042386","32.443501"],["GABS","FAOR","Modibo Keita International Airport","12.5335","-7.94994"]],"errors":false}

Related

How to update Chart.js based on dropdown list?

UPDATED
I have added a dropdown to my chart which allows the user to select among the available operator names.
I need your help so that when selecting an available operator name, the graphic is updated showing only the information of the selected operator.
From all my JSON response, for this example it should only show the information in a red box:
As you can see in the image, if I select the Luis operator, this graph should update and show me only the Luis operator (he has 2 work orders in finished state).
Below my report.js file which I use to make the graph.
getChartData () method:
I use ajax, basically I'm getting the data and loading my select with the names of the available operators.
renderChart () method:
 
I am passing it as a parameter "label and data" with these parameters I can make my graph also I am configuring some available options.
select.on ('change', function ():
here I do not understand how to tell my chart to update depending on the option selected, then I would have to call the renderChart method again to graph again with the selected data but it does not work, I do not know how to solve it, it is what I am trying.
report.js
function getChartData(user) {
$.ajax({
url: '/admin/reports/getChart/' + user,
type: 'GET',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
dataType: 'json',
success: function (response) {
console.log(response);
var data = [];
var labels = [];
for (var i in response.orders) {
data.push(response.orders[i].orders_by_user);
labels.push(response.orders[i].name);
$("#operator").append('<option value='+response.orders[i].id+'>'+response.orders[i].name+'</option>');
}
renderChart(data, labels);
},
error: function (response) {
console.log(response);
}
});
}
function renderChart(data, labels) {
var ctx = document.getElementById("orders").getContext('2d');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Terminadas',
data: data,
borderColor: 'rgba(75, 192, 192, 1)',
backgroundColor: "#229954",
borderWidth: 1,
yAxisID: 'Ordenes',
xAxisID: 'Operarios',
}]
},
options: {
scales: {
yAxes: [{
id: "Ordenes",
ticks: {
beginAtZero: true
},
scaleLabel: {
display: true,
labelString: 'Ordenes'
}
}],
xAxes: [{
id: "Operarios",
scaleLabel: {
display: true,
labelString: 'Operarios'
}
}],
},
title: {
display: true,
text: "Ordenes en estado terminado"
},
legend: {
display: true,
position: 'bottom',
labels: {
fontColor: "#17202A",
}
},
}
});
function updateChart() {
myChart.destroy();
myChart = new Chart(ctx, {
type: document.getElementById("operator").value,
data: data
});
};
}
getChartData();
$('#operator').select2({
placeholder: 'Selecciona un operario',
tags: false
});
var select = $('#operator');
var pElem = document.getElementById('p')
select.on('change', function() {
var item = $(this).val();
pElem.innerHTML = 'selectedValue: ' + item;
var data = {
labels: labels,
datasets: data
}
var ctx = document.getElementById("orders").getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: data
});
});
My select:
<select class="form-control" name="operator" id="operator">
<option></option>
</select>
I get lost trying to link the selected option and the information to show (update the graph). Could you please tell me how to solve this?
UPDATED 1
My select:
<select class="form-control" name="operator" id="operator">
<option></option>
</select>
Through ajax I load my select options:
for (var i in response.orders) {
order.push(response.orders[i].orders_by_user);
user.push(response.orders[i].name);
$("#operator").append('<option value='+response.orders[i].id+'>'+response.orders[i].name+'</option>');
}
renderChart(order, user);
With the answer you have given me, modify my report.js file exactly my function renderChart(order, user) and it is as follows:
function renderChart(order, user) {
var ctx = document.getElementById("orders").getContext('2d');
var myChart = new Chart(ctx, {
//code...
});
//my select
var selectOption = $('#operator');
selectOption.on('change', function() {
var option = $("#operator").val();
myChart.data.labels = option;
if (option == 'All') {
myChart.data.labels = user,
myChart.data.datasets[0].data = order;
} else {
myChart.data.labels = option;
myChart.data.datasets[0].data = order;
}
myChart.update();
});
}
The graph is updated incorrectly an error occurs you can see it in the image:
Obviously if I select the "All" option, it shows and graphs correctly, now if I select "jose" the following happens:
The graph does not respect the scale, I know that Jose has only 1 work order, and up to 2 on the scale.
On the x axis instead of showing me the name in this case "Jose" is showing me the selection id which in this case is 6.
The same happens with the option "Miguel".
Please help me correct this section:
var selectOption = $('#operator');
selectOption.on('change', function() {
var option = $("#operator").val();
myChart.data.labels = option;
if (option == 'All') {
myChart.data.labels = user,
myChart.data.datasets[0].data = order;
} else {
myChart.data.labels = option;
myChart.data.datasets[0].data = order;
}
myChart.update();
});
When the selected options changes, you must not destroy the chart. All you need to do is performing the following steps.
Change the data.labels
Change the data of the unique dataset
Update the chart itself
This is basically done as follows.
myChart.data.labels = <new labels>;
myChart.data.datasets[0].data = <new values>;
myChart.update();
The following example illustrates how this can be done in JavaScript.
orders = [
{ name: 'Luis', orders_by_user: '2' },
{ name: 'Jose', orders_by_user: '1' },
{ name: 'Miguel', orders_by_user: '3' }
];
const myChart = new Chart(document.getElementById('orders'), {
type: 'bar',
data: {
labels: orders.map(o => o.name),
datasets: [{
label: 'Terminadas',
data: orders.map(o => o.orders_by_user),
borderColor: 'rgba(75, 192, 192, 1)',
backgroundColor: "#229954",
borderWidth: 1,
yAxisID: 'Ordenes',
xAxisID: 'Operarios',
}]
},
options: {
scales: {
yAxes: [{
id: "Ordenes",
ticks: {
beginAtZero: true,
stepSize: 1
},
scaleLabel: {
display: true,
labelString: 'Ordenes'
}
}],
xAxes: [{
id: "Operarios",
scaleLabel: {
display: true,
labelString: 'Operarios'
}
}],
},
title: {
display: true,
text: "Ordenes en estado terminado"
},
legend: {
display: true,
position: 'bottom',
labels: {
fontColor: "#17202A",
}
},
}
});
orders.forEach(o => {
const opt = document.createElement('option');
opt.value = o.name;
opt.appendChild(document.createTextNode(o.name));
document.getElementById('operator').appendChild(opt);
});
function refreshChart(name) {
myChart.data.labels = [name];
if (name == 'All') {
myChart.data.labels = orders.map(o => o.name),
myChart.data.datasets[0].data = orders.map(o => o.orders_by_user);
} else {
myChart.data.labels = [name];
myChart.data.datasets[0].data = orders.find(o => o.name == name).orders_by_user;
}
myChart.update();
}
Operarios:
<select id="operator" onchange="refreshChart(this.value)">
<option>All</option>
</select>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<canvas id="orders" height="90"></canvas>

How to show multiple highcharts on selection of few parameters and dynamically load JSON data using PHP page?

I have two parameters to load dynamic json data from mysql and visualise multiple line charts on page submit.
$.ajax({
url: 'get_pubmedid.php',
type: 'get',
data: {org: org, ptype: ptype, path: path,mirna: mirna},
dataType: 'json',
success:function(response) {
var len = response.length;
for( var i = 0; i<len; i++) {
pubmed = response[i]['name'];
cell=response[i]['cell'];
alert(cell+" "+pubmed+" "+len);
var cells=encodeURIComponent(cell);
var cname="charts"+(i+1);id=i+1;var pid=i+1;
var container = cname;
var func_name = cname;
func_name = function () {
Highcharts.chart(container, {
showhighcharts(org,ptype,path,mirna,cell,cells,pid,pubmed,cname,id);
}
}
func_name()
}
}
});
function showhighcharts(org,ptype,path,mirna,cell,cells,pid,pubmed,cname,id) {
$("#"+cname).html("Wait, Loading graph...");
var options = {
chart: {
type: 'line',
renderTo: cname
},
colors: ['#058DC7', '#50B432', '#ED561B', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263', '#6AF9C4'],
credits: {
enabled: false
},
title: {
text: 'Temporal Viewer',
x: -20
},
xAxis: {categories:<?php //echo $_SESSION["cat"]; ?>,
offset:2,
title: {enabled: true,text: 'Time Point' }
},
tooltip: {
shared: true,
useHTML: true,
headerFormat: '<b>Time Point:{point.key}</b> <table style="width:200px;font-size:12px;font-weight:bold;">',
pointFormat: '<tr><td>Dosage:</td><td style="color: {series.color}">{series.name} </td></tr>' + '<tr><td>Fold Change:</td><td style="color: {series.color}">{point.y} </td></tr>',
footerFormat: '</table>',
enabled: true,
crosshairs: {
color: 'light gray',
dashStyle: 'longdash'
}
},
plotOptions: {
series: {
dashStyle: 'longdash'
},
line: {
dataLabels: {
enabled: true
},
enableMouseTracking: true
}
},
series: [{}]
};
$.ajax({
url: "jdatas.php?org="+org+"&ptype="+ptype+"&path="+path+"&mirna="+mirna+"&pid="+id+"&cell="+cell+"&pub="+pubmed,
data: 'show=impressions',
type:'get',
dataType: "json",
success: function(data){
var getSeries = data;
options.series = getSeries;
var chart1 = new Highcharts.Chart(options);
}
});
I want multiple graphs to be loaded on submit.
But its not showing any graph.

Passing array data to Morris Chart using JSON

I want to pass dynamic array data to Morris Charts from my Ajax Success return.
I arrive to get all data for the line chart.
How to do with this code to send data.json and data.y in the this.createAreaChartDotted parameters?
!function($) {
"use strict";
var MorrisCharts = function() {};
//creates area chart with dotted
MorrisCharts.prototype.createAreaChartDotted = function(element, pointSize, lineWidth, data, xkey, ykeys, labels, Pfillcolor, Pstockcolor, lineColors) {
Morris.Area({
element: element,
pointSize: 3,
lineWidth: 1,
data: data,
xkey: xkey,
ykeys: ykeys,
labels: labels,
hideHover: 'auto',
pointFillColors: Pfillcolor,
pointStrokeColors: Pstockcolor,
resize: true,
gridLineColor: '#eef0f2',
lineColors: lineColors
});
},
MorrisCharts.prototype.init = function() {
var id_transmetteur = $('#id_transmetteur').val();
var table_name = $('#table_name').val();
var category_table = $('#category_table').val();
$.ajax({
method:"post",
dataType: 'json',
url: $('#ajax').val()+'getDataCapteurs.php',
success: function(data){
if(data.status == 'success'){
console.log(data.json); //Replace $areaDotData
console.log(data.y); //Replace ['a', 'b'] in this.createAreaChartDotted()
} else if(data.status == 'error'){
if(data.messages.length>0){
var i;
for (i = 0; i < data.messages.length; ++i) {
if(data.messages[i][0] == 'error'){
console.log('error');
}
}
}
}
}
});
//creating area chart with dotted
var $areaDotData = [
{ y: '2009', a: 10, b: 20 },
{ y: '2010', a: 75, b: 65 },
{ y: '2011', a: 50, b: 40 },
{ y: '2012', a: 75, b: 65 },
{ y: '2013', a: 50, b: 40 },
{ y: '2014', a: 75, b: 65 },
{ y: '2015', a: 90, b: 60 }
];
this.createAreaChartDotted('morris-area-with-dotted', 0, 0, $areaDotData, 'y', ['a', 'b'], ['Series A', 'Series B'],['#ffffff'],['#999999'], ['#52bb56', '#ebeff2']);
},
//init
$.MorrisCharts = new MorrisCharts, $.MorrisCharts.Constructor = MorrisCharts
}(window.jQuery),
//initializing
function($) {
"use strict";
$.MorrisCharts.init();
}(window.jQuery);
I tried to declare a variable after
MorrisCharts.prototype.init = function(){
var data_chart; ...} and in ajax success : data_chart = data.json but when I tested my variable, she is undefined.
Thanks for helps.
You won't be able to access that data from outside the success callback in your ajax call. So instead, do whatever you need to do within the success callback. Try initializing the Morris chart from within the ajax call.
!function($) {
"use strict";
var MorrisCharts = function() {};
//creates area chart with dotted
MorrisCharts.prototype.createAreaChartDotted = function(element, pointSize, lineWidth, data, xkey, ykeys, labels, Pfillcolor, Pstockcolor, lineColors) {
Morris.Area({
element: element,
pointSize: 3,
lineWidth: 1,
data: data,
xkey: xkey,
ykeys: ykeys,
labels: labels,
hideHover: 'auto',
pointFillColors: Pfillcolor,
pointStrokeColors: Pstockcolor,
resize: true,
gridLineColor: '#eef0f2',
lineColors: lineColors
});
},
MorrisCharts.prototype.init = function(data, yData) {
this.createAreaChartDotted('morris-area-with-dotted', 0, 0, data, 'y', yData, ['Series A', 'Series B'],['#ffffff'],['#999999'], ['#52bb56', '#ebeff2']);
},
//init
$.MorrisCharts = new MorrisCharts, $.MorrisCharts.Constructor =
MorrisCharts
}(window.jQuery),
function($) {
"use strict";
var id_transmetteur = $('#id_transmetteur').val();
var table_name = $('#table_name').val();
var category_table = $('#category_table').val();
$.ajax({
method:"post",
dataType: 'json',
url: $('#ajax').val()+'getDataCapteurs.php',
success: function(data){
if(data.status == 'success'){
var data = data.json;
var yData = data.y;
//Send data & Yaxis
$.MorrisCharts.init(data, yData);
} else if(data.status == 'error'){
if(data.messages.length>0){
var i;
for (i = 0; i < data.messages.length; ++i) {
if(data.messages[i][0] == 'error'){
console.log('error');
}
}
}
}
}
});
}(window.jQuery);

ChartJS and Ajax calls

I would like to make charts using ChartJS and PHP ( Silex Framework )
This is my ajax call
$.ajax({ url: 'stats',
data: {method: 'dossierRepartitionType'},
type: 'post',
datatype: 'json',
success: function(output) {
dataDossierRepartitionType=output;
},
error: function () {
alert("Oops there is an error.");
}});
This is my PHP function which i managed to call
public function dossier(){
$stmt = "SELECT count(*) FROM dossier GROUP BY typedossier";
$stmt = $this->db->prepare($stmt);
$rows=$stmt->execute();
$rows = $stmt->fetch(PDO::FETCH_NUM);
return ?????
}
And here is my chart :
var ctx = document.getElementById("myChart");
ctx.width = 400;
ctx.height = 400;
data = {
datasets: [{
data: [dataDossierRepartitionType, 20],
backgroundColor: [
'rgb(255, 99, 132)',
'rgb(54, 162, 235)',
],
borderColor: [
'white',
'white',
],
borderWidth: 1
}],
// These labels appear in the legend and in the tooltips when hovering different arcs
labels: [
'Red',
'Blue',
]
};
var myDoughnutChart = new Chart(ctx, {
type: 'doughnut',
data: data,
options: {
legend: {
labels: {
fontColor: "white",
fontSize: 18
}
},
maintainAspectRatio: false,
responsive: false
}
});
Route.php
$app->post('/stats', function () use ($app) {
session_start();
if(isset($_POST['method']) && !empty($_POST['method'])) {
$method = $_POST['method'];
switch($method) {
case 'dossierRepartitionType' :
$dossiers=$app['dao.dossier']->dossierRepartitionType();
break;
}
}
return new ResponseSilex("$dossiers");
});
So my AJAX call the route and then get the result of the function into $dossiers which is ouput in the Reponse, am i doing it right ?
How can i return an array with all the datas value for each count ?
I struggle to catch error and to find a proper way to bind MYSQL count value to my chart
Thank you
The main idea is that you should format your data in your model, then return JSON to the front end via json_encode. After that, you would parse the json in your ajax returns and then pass the appropriate data to the chart.
it's very easy, you need to modify your php code like this:
public function dossier(){
$stmt = "SELECT count(*) as total FROM dossier";
$stmt = $this->db->prepare($stmt);
$rows=$stmt->execute();
$number_of_rows = $rows->fetchColumn();
return json_encode(["total" => $number_of_rows]);
In your ajax petition you are specifying a "json" return so in your script php need's return a json.
$.ajax({ url: 'stats',
data: {method: 'dossierRepartitionType'},
type: 'post',
datatype: 'json',
success: function(output) {
dataDossierRepartitionType=output.total;
},
error: function () {
alert("Oops there is an error.");
}});
You should to receive a json from php with this structure
{total: rows_total}
so in your ajax response you'll receive that answer and you can get the data like this:
dataDossierRepartitionType=output.total;
Sorry for my english, hope can help you
You can send JSON data from php
Try this:
Php:
public function dossier(){
$stmt = "SELECT count(*) FROM dossier GROUP BY typedossier";
$stmt = $this->db->prepare($stmt);
$rows=$stmt->execute();
$rows = $stmt->fetch(PDO::FETCH_NUM);
exit(json_encode(array('counts' => $rows)));
}
After ajax successfully complete you need to initialize chart plugin inside success callback like below:
Ajax:
$.ajax({ url: 'stats',
data: {method: 'dossierRepartitionType'},
type: 'post',
datatype: 'json',
success: function(output) {
if (output.counts) {
dataDossierRepartitionType=output.counts.join();
alert(dataDossierRepartitionType)
initCharts(dataDossierRepartitionType);
}
},
error: function () {
alert("Oops there is an error.");
}});
Finally wrap chart initialization code inside callback function
Chart:
function initCharts(dataDossierRepartitionType){
var ctx = document.getElementById("myChart");
ctx.width = 400;
ctx.height = 400;
data = {
datasets: [{
data: [dataDossierRepartitionType, 20],
backgroundColor: [
'rgb(255, 99, 132)',
'rgb(54, 162, 235)',
],
borderColor: [
'white',
'white',
],
borderWidth: 1
}],
// These labels appear in the legend and in the tooltips when hovering different arcs
labels: [
'Red',
'Blue',
]
};
var myDoughnutChart = new Chart(ctx, {
type: 'doughnut',
data: data,
options: {
legend: {
labels: {
fontColor: "white",
fontSize: 18
}
},
maintainAspectRatio: false,
responsive: false
}
});
}

How can I convert datetime stamp in jQuery of a Highchart to get the correct format in json?

To start with I must confess I have not so good knowledge of jQuery and Json.
Basically my json encode reads like this ["2013-06-18 09:42:30",6.21],["2013-06-18 09:44:30",6.57],["2013-06-18 10:01:49",6.61],......these are the results of battery voltage in given date and time which keeps updating. There are hundreds of records.
I know this time stamp is not valid while plotting the graph so Yesterday I was trying to tweak the jQuery in jSfiddle to get result and convert it into a chart.
While working in Jsfiddle it said my code is fine but I am getting a blank container area.
Can anyone please guide me on how to convert the datetime stamp in UTC so that a graph can be plotted.
The jQuery which I was tweaking looks like this:
var chart;
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
defaultSeriesType: 'spline',
events: {
load: requestData
}},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
month: '%e. %b',
year: '%b'
}
},
yAxis: {
title: {
text: 'Battery Voltage'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
Highcharts.dateFormat('%a %d %b %H:%M:%S', this.x) +' : '+ this.y +" V";
}
},
series: [{
name: 'Battery Volatge',
data: []
}]
});
function requestData() {
$.ajax({
url: 'data.php',
datatype: "json",
success: function(data) {
alert(data);
chart.series[0].setData(data);
},
cache: false
});
}
and my PHP looks like this:
<?php
header("Content-type: text/json");
$dbc = mysql_connect('xxxxx','xxxxx','xxxxx') or die(mysql_error());
mysql_select_db('xxxxx',$dbc) or die(mysql_error());
$result = mysql_query("SELECT COUNT(*) AS count FROM Station_State");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$SQL = "SELECT ss_Stamp,ss_BatteryStatus FROM Station_State WHERE Station_State_Index > 371298 AND ss_Station_idx = 34 ORDER BY ss_Stamp";
$result = mysql_query( $SQL ) or die("Couldn?t execute query.".mysql_error());
$i=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$row[ss_BatteryStatus] = (float) $row[ss_BatteryStatus];
$rows[$i]=array($row[ss_Stamp],$row[ss_BatteryStatus]);
$i++;
}
echo json_encode($rows);
?>
It is probably a basic question but I am still learning so any advice will be appreciated. Do let me know if you need any more information or anything I mentioned sounds vague.
Thanks
You can simple preprocess your data. Before setting data loop through all points, and convert that string to timestamp, for example:
for (var i = 0; i < data.length; i++ ){
data[i][0] = new Date(data[i][0]).getTime();
}
Posting Code which works perfectly. The only problem is the a window pops up with encoded data.
jQuery code:
$(function () {
$(document).ready(function() {
Highcharts.setOptions({
global: {
useUTC: false
}
});
var chart;
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
defaultSeriesType: 'spline',
borderwidth: 0,
events: {
load: requestData
}},
title: {
text: 'Battery Graph'
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
month: '%e. %b',
year: '%b'
}
},
yAxis: {
title: {
text: 'Battery Performance Voltage'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
Highcharts.dateFormat('%a %d %b %H:%M:%S', this.x) +' : '+ this.y +" V";
}
},
series: [{
showInLegend: false,
name: 'Time vs Volatge',
data: []
}]
});
function requestData() {
$.ajax({
url: 'bdata.php',
datatype: "json",
success: function(data) {
alert(data);
for (var i = 0; i < data.length; i++ ){
data[i][0] = new Date(data[i][0]).getTime();
}
chart.series[0].setData(data);
},
cache: false
});
};
});
});
My PHP code looks like this:
<?php
header("Content-type: text/json");
$dbc = mysql_connect('xxxx','xxxx','xxxx') or die(mysql_error());
mysql_select_db('xxxx',$dbc) or die(mysql_error());
$result = mysql_query("SELECT COUNT(*) AS count FROM xxxx");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$SQL = "SELECT ss_Stamp,ss_BatteryStatus FROM Station_State WHERE Station_State_Index > 377708 AND ss_Station_idx = 34 ORDER BY ss_Stamp";
$result = mysql_query( $SQL ) or die("Couldn?t execute query.".mysql_error());
$i=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$row[ss_BatteryStatus] = (float) $row[ss_BatteryStatus];
$rows[$i]=array($row[ss_Stamp],$row[ss_BatteryStatus]);
$i++;
}
echo json_encode($rows);
?>
Thank you Pawel. You have been great help.

Categories