0

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 を使用することはできますか? または、これを行う別の方法はありますか?

よろしくお願いします。

4

2 に答える 2

1

メソッドでは、 のプロパティを$.ajax()使用できます。dataoptions

例:

               var jsonData = $.ajax({
                    url: "test3.php",
                    dataType: "json",
                    async: false,
                    data: { 'playerID' : 123 }
                }).responseText;

SYNC コマンドに関するあなたの質問に対する私のコメントをフォローアップします...callback次の関数を起動するために利用可能なメソッドを使用する必要があります。

于 2013-06-27T20:49:21.843 に答える
-1

URLからパラメータを取得するために使用test3.php?player=your_idおよび使用できます$playerid = (int)$_GET['player'];

于 2013-06-27T20:47:36.017 に答える