2015-04-03 61 views
0

我不是php的專家,但我在這裏卡住了。我有以下三個.php文件php post和重定向頁面同時

  1. 的index.php < - 下拉列表中,選擇哪個數據庫表。

  2. query.php < - 它製作json查詢。

  3. chart.php < - 它是高級JQuery頁面。其中使用$.getJSON("query.php", function(json) {函數從query.php文件中獲取數據。

index.php將選擇DB /表的下拉列表中獲取用戶的輸入,並把它傳遞給query.php並設置SELECT * FROM $table變量。

但我想要做POST並在同一時間它將打開chart.php頁面,所以我可以直接重定向到圖表頁面。我如何發送POST和重定向同時如此query.php得到$表變量,並立即chart.php打開圖表。

編輯:

如果我把我所有的query.php代碼中chart.php那我怎麼把這些JSON值$.getJSON()

$.getJSON("query.php", function(json) { 
       options.xAxis.categories = json[0]['data']; 
       options.series[0] = json[1]; 
       options.series[1] = json[2]; 
       options.series[2] = json[3]; 
       chart = new Highcharts.Chart(options); 
      }); 

$.getJSON()如何從變量中獲取值?

+0

你可以用'success'嘗試它甚至jQuery中的每個動作本身? – 2015-04-03 16:41:53

+0

您可以更改您的代碼以將發佈的值保存爲'$ _SESSION'值,或者將表單/值直接發佈到'chart.php',並將其作爲參數添加到您的'$ .getJSON()' – Sean 2015-04-03 16:44:29

+0

@Sean - 我喜歡你的第二個想法,但我怎麼把'json'輸出值放在'$ .getJSON()'函數中?請參閱我已編輯我的問題 – Satish 2015-04-03 17:10:44

回答

1

1)從的index.php - >使POST請求與需要的參數使用$ _POST上chart.php =>從index.php中接收數據,並顯示在諸如模板

2)chart.php:

的GET請求query.php

$.getJSON("query.php?<?='param1='.$_POST['param1']?>", function(json) { 
       options.xAxis.categories = json[0]['data']; 
       options.series[0] = json[1]; 
       options.series[1] = json[2]; 
       options.series[2] = json[3]; 
       chart = new Highcharts.Chart(options); 
      }); 

或使用通常的$就要求通過POST請求發送:

$.ajax({ 
     url: 'query.php', 
     data: "<?='param1='.$_POST['param1']?>" 
     dataType : "json", 
     method:"POST", 
     success: function(json){ 
       options.xAxis.categories = json[0]['data']; 
       options.series[0] = json[1]; 
       options.series[1] = json[2]; 
       options.series[2] = json[3]; 
       chart = new Highcharts.Chart(options); 
}); 

UPDATE

如果您的服務器沒有short_open_tag的值爲=開 - 使用<?php echo 'param1='.$_POST['param1'] ?>

,並讓他們在模板前檢查PARAMS

+0

in'query。php'我試圖在'SQL'查詢中嵌入'$ _GET [param1]',但它沒有工作,我做對了嗎? ('SipResponseCode LIKE'2%'),SUM(SipResponseCode LIKE'4%')AS'4xx','$ query = mysql_query(「SELECT DATE_FORMAT(AcctStartTime,'%d%b')AS Days, SUM(SipResponseCode LIKE'5%')AS'5xx'FROM'「。$ _GET [」param1「]。」'GROUP BY DATE(AcctStartTime);「)or die(」Dadasdad「);' – Satish 2015-04-03 18:57:24

+0

Nevermind,I figure瞭解如何將變量傳遞給'sql'查詢,謝謝 – Satish 2015-04-03 19:14:42