Vote count:
0
I have employee table in mysql database Table columns as.. empno ename sal...etc I am creating custom query page..where user will type there query in textarea and then click on submit button..I want to retrive data from mysql according to user requested column and want to show google chart table.
I tried through JSON but no luck
Following code is what i did...
Enter custom query here...
Fire .php page...
$con = mysqli_connect($db_host,$db_username,$db_pass) or die ("could not connect to mysql");
mysqli_select_db($con,$db_name) or die ("no database");
//query all records from the database
$query=$_POST['query'];
$returnArray = array();
$result = mysqli_query($con,$query);
while($rs = mysqli_fetch_array($result, MYSQL_ASSOC))
{
$returnArray[] = $rs;
}
$fp = fopen('sampledata.json', 'w+');
fwrite($fp, json_encode($returnArray));
fclose($fp);
}
?>
<script type="text/javascript" src="http://ift.tt/JuZcy0"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1', {'packages':['table']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
function drawChart() {
var jsonData = $.ajax({
url: "getdata.php",
dataType:"json",
async: false
}).responseText;
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(jsonData);
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.Table(document.getElementById('chart_div'));
chart.draw(data, {width: 700, height: 400});
}
</script>
<div id="chart_div"></div>
</html>
getdata.php
Please advise on this as I am not getting table chart
asked 20 secs ago
How to read and write data from mysql to JSON and then use for google table chart
Aucun commentaire:
Enregistrer un commentaire