我找不到任何我的問題的答案。 我使用PhPmyGraph(http://phpmygraph.abisvmm.nl/)來顯示我的數據庫中某些數據的圖形。 問題是我必須在文件本身中創建我的數組,如果我想在頁面上創建2個圖形,我需要創建2個不同的文件。 顯然,該文件更容易與CMS一起使用,但我沒有使用它。PHPmyGraph:用GET發送一個數組
這是文件graph.php:
<?php
//Set content-type header for the graphs
header("Content-type: image/png");
//Include phpMyGraph5.0.php
include_once('../phpMyGraph5.0.php');
//Set config directives
$cfg['title'] = 'Example graph';
$cfg['width'] = 500;
$cfg['height'] = 250;
//Set data
$data = array(
'Jan' => 12,
'Nov' => 78,
'Dec' => 23
);
//Create phpMyGraph instance
$graph = new phpMyGraph();
//Parse
$graph->parseVerticalPolygonGraph($data, $cfg);
?>
我把它在我的網頁的index.php:
echo " < img src=\"graph.php\"> ";
有另一種方式做到這一點?並將數據從index.php發送到graph.php? 或者將代碼graph.php移動到index.php中?問題是圖像對象,我真的不知道該怎麼做!
UPDATE: 我幾乎找到了解決辦法,我的代碼是現在:
//Parse
$graph->parseVerticalPolygonGraph(unserialize($_GET['data']), $cfg);
的index.php:
$select_daily = mysql_query("SELECT * FROM table");
while ($row_daily = mysql_fetch_assoc($select_daily)){
$y = substr($row_daily['ymd'], 0, -4); // Year
$m = substr($row_daily['ymd'], 4, -2); // Month
$d = substr($row_daily['ymd'], -2); // Day
$key = $d."/".$m."/".$y;
$data_daily [$key] = $row_daily['members'];
}
foreach($data_daily as $key => $value) {
echo $key ,' : ', $value ,'<br/>';
}
echo "< img src=\"graph.php?data=".serialize($data_daily)."\">";
但我
在graph.php得到錯誤「提供的數據不是數組」
我看不出它有什麼問題? 如果我做的var_dump($ data_daily)獲得:
陣列(8){[ 「14/12/2011」] =>串(1)爲 「0」[ 「13/12/2011」] => string(2) 「11」[「12/12/2011」] => string(1)「0」[「11/12/2011」] => string(1)「2」 [「10/2011/12/2011「] => string(1)」9「[」09/12/2011「] => string(1)」3「 [」08/12/2011「] => string(1)」 6" [ 「07/12/2011」] =>串(1) 「6」}
UPDATE2:
的var_dump($ DATA1);給出:
array(12) { ["Jan"]=> int(12) ["Feb"]=>
int(25) ["Mar"]=> int(0) ["Apr"]=> int(7) ["May"]=> int(80) ["Jun"]=>
int(67) ["Jul"]=> int(45) ["Aug"]=> int(66) ["Sep"]=> int(23)
["Oct"]=> int(23) ["Nov"]=> int(78) ["Dec"]=> int(23) }
和的var_dump($ s_data1 =序列化($ DATA1))給出:
a:12:s:3:"Jan";i:12;s:3:"Feb";i:25;s:3:"Mar";i:0;s:3:"Apr";i:7;s:3:"May";i:80;s:3:"Jun";i:67;s:3:"Jul";i:45;s:3:"Aug";i:66;s:3:"Sep";i:23;s:3:"Oct";i:23;s:3:"Nov";i:78;s:3:"Dec";i:23;}
然後反序列化($ s_data1);給出比$數據1
同樣的事情,所以解析的參數1應該是正確的......我看不出有什麼不對
我終於放棄了,裝我的陣列,圖表。PHP:
if ($_GET['data'] == 'daily'){
$cfg['title'] = 'daily';
$graph->parseVerticalPolygonGraph($data_daily, $cfg);
}
我呼籲這樣的文件:
echo "<img src=\"graph.php?data=daily\">";
感謝您的幫助反正
它並沒有幫助。仍然由graph.php返回相同的錯誤。我試圖做urlencode(json_encode($ data_daily)和解碼在另一邊,但它是相同的... – remyremy 2011-12-14 19:45:10
什麼打印出來,如果你var_dump(反序列化($ _ GET ['data'])) – 2011-12-14 20:33:04