简体   繁体   English

将变量从Google Chart脚本传递到MySql PHP

[英]Passing a variable from Google Chart script to MySql PHP

I need to pass a variable from a $ _GET [ 'variableID'], prior to the script of Google chart and then to the destination page PHP to determine which client I want to do the query. 我需要从$ _GET ['variableID']传递一个变量,在Google图表的脚本之前,然后到目标页面PHP,以确定我想要查询哪个客户端。 How could I? 我怎么能? (Note: I am not a genius in javascript). (注意:我不是javascript的天才)。 Thank you very much!! 非常感谢你!!

This is the chart.js where i define 这是我定义的chart.js

/* Get data from the database */
function getData() {
    jQuery.ajax({
        url: 'get.php',
        type: 'GET',
        dataType: 'json',
        mimeType: 'multipart/form-data',
        contentType: false,
        cache: false,
        processData: false,
        success: function( data, jqXHR ) {
            if( data == "null" ) {
                // just in case
            } else {
                drawGraph( data );
            }
        },
        error: function( textStatus ) {
            console.log(" error. damm. ");
        }
    });
}

/* Initialization of Google Charts API */
google.load( "visualization" , "1", { packages: [ "corechart" ] });
google.setOnLoadCallback( getData );

/* Chart to render time-user graphs */
function drawGraph( data ) {
    for( var i = data.length; i > 0; i-- ) {
        data[i] = data[i - 1];
    }
    data[0] = [ 'Data', 'Comandes' ];
    console.log( data );
    var chartData = google.visualization.arrayToDataTable( data );var options = {
      title: '','legend':'none','chartArea': {'width': '100%', 'height': '80%'},

backgroundColor: {
    stroke: '#a5a5a5',
    strokeWidth: 1
},


      hAxis: {
        format: 'M/d/yy',
        gridlines: {count: 15}
      },
      vAxis: {
        gridlines: {color: '#d0d0d0'},
        minValue: 0
      }
    };

    var chart = new google.visualization.LineChart( document.getElementById( 'chart_div' ) );

    chart.draw( chartData , options );
}

And this is the get.php (pay special attention to WHERE idclient=GET variableID ) 这是get.php(特别注意WHERE idclient = GET variableID

  include('lib/connection.php');

 if($_GET) {
$query = "select DATE( data ), COUNT(*)
            from smarty_pedidos  **WHERE idclient=GET variableID**
            group by DATE( data )";
$result = mysql_query( $query );
$rows = array();
while( $row = mysql_fetch_array( $result ) ) {
    $rows[] = array( '0' => $row['0'] , '1' => $row['1'] );

}

//print json_encode($rows);
print json_encode($rows, JSON_NUMERIC_CHECK);
 }

in your ajax call, add the variable to the url... 在你的ajax调用中,将变量添加到url中...

jQuery.ajax({
  url: 'get.php?variableID=variableVALUE',
  ...  

then in php code, use $_GET['variableID'] 然后在PHP代码中,使用$_GET['variableID']

$query = "select DATE( data ), COUNT(*)
  from smarty_pedidos  WHERE idclient=$_GET['variableID']
  group by DATE( data )";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM