PHP と MySQL で Google Charts API を使い始めたばかりで、少し助けていただければ幸いです。Google Charts が使用する MySQL クエリの結果が変数に基づいていることを望みます。基本的に私はこれを持っており、期待どおりに動作します。
displayChart.php
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('visualization', '1', { packages: ['corechart'] });
google.setOnLoadCallback(drawChart);
function drawChart() {
var jsonData = $.ajax({
url: "test3.php",
dataType: "json",
async: false
}).responseText;
var data = new google.visualization.DataTable(jsonData);
var options = {
fontName: 'Trebuchet MS',
colors: ['#22671F'],
title: 'Handicap History',
hAxis: {title: 'Revision Date', titleTextStyle: {color: 'red'}}
};
var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
test3.php
$result = $connect->query("SELECT rev_date, ndx FROM revisions WHERE player_id=7");
$table = array();
$table['cols'] = array(
array('label' => 'Rev', 'type' => 'string'),
array('label' => 'Index', 'type' => 'number')
);
$rows = array();
while ($nt = $result->fetch_assoc())
{
$temp = array();
$temp[] = array('v' => $nt['rev_date']);
$temp[] = array('v' => $nt['ndx']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
echo $jsonTable;
私はtest3.phpでこのようなことができるようにしたいと思います
$result = $connect->query("SELECT rev_date, ndx FROM revisions WHERE player_id='$playerID'");
$table = array();
$table['cols'] = array(
array('label' => 'Rev', 'type' => 'string'),
array('label' => 'Index', 'type' => 'number')
);
$rows = array();
while ($nt = $result->fetch_assoc())
{
$temp = array();
$temp[] = array('v' => $nt['rev_date']);
$temp[] = array('v' => $nt['ndx']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
echo $jsonTable;
$playerID 変数の値を test3.php ページに渡すにはどうすればよいですか? ajax でピースが呼び出されたときに変数を渡して、url: "test3.php"
test3.php で $_GET を使用することはできますか? または、これを行う別の方法はありますか?
よろしくお願いします。