can anyone help me how to run this code in php. i copy google chart code then add while condition to display my query. but nothing happen when run this code.
<?php
include("includes/mssqlconn.php");
?>
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['AgentName', 'Transaction', 'Amount'],
<?php
$conn->open($connStr); //Open the connection to the database
$conn->CommandTimeout = 1000;
//declare the SQL statement that will query the database
$query = "select top 10 a.Account
,COUNT(txn) as TxnCount
,sum([amountloc]) as Amount
from table a
where (Dateloc between '20170201' and '20170205')
group by a.Account
order by TxnCount desc";
$rs = $conn->execute($query);
while (!$rs->EOF) //carry on looping through while there are records
{
?>
['<?php echo $rs->Fields["a.account"]->Value;?>', '<?php echo $rs->Fields["txncount"]->Value;?>', '<?php echo $rs->Fields["amount"]->Value;?>'],
]);
<?php
$rs->MoveNext();
}
$rs->Close();
$conn->Close();
$rs = null;
$conn = null;
?>
var options = {
title: 'Performance',
curveType: 'function',
legend: { position: 'bottom' }
};
var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="curve_chart" style="width: 900px; height: 500px"></div>
</body>
</html>
my connection is ado.connection and I am using MSSQL 2008. any help will do.
i found my error. just replace above code to this.
while (!$rs->EOF) //carry on looping through while there are records
{
?>
['<?php echo $rs->Fields["a.account"]->Value;?>', '<?php echo $rs->Fields["txncount"]->Value;?>', '<?php echo $rs->Fields["amount"]->Value;?>'],
<?php
$rs->MoveNext();
}
?>
]); //the problem is here
<?php
$rs->Close();
$conn->Close();
$rs = null;
$conn = null;
?>