請問一下
我的CSV檔(ABC_200522.CSV)
time,DEF,ABC
01:01:00,-0.0153,0.0156
00:00:01,-0.0153,-0.0457
00:00:02,-0.0353,-0.0158
00:00:03,-0.0353,-0.1944
00:00:04,-0.0353,-0.5211
00:00:05,-0.0353,-0.4318
00:00:06,-0.0353,-0.0251
00:00:07,-0.0353,-0.1195
00:00:08,-0.0353,-0.6572
00:00:09,-0.0353,-0.2845
00:00:10,-0.0353,-0.5612
00:00:11,-0.0353,-0.8812
第一個PHP(value.php)
<?php
$dirname="pchart/csv/";
$dh=opendir($dirname);
$keyword = ABC;
$date = 200522;
$rows = 2;
while ($dave=readdir($dh))
{
if ($dave != "." && $dave != "..") {
if (preg_match("/$keyword/i",$dave)){
if (preg_match("/$date/i",$dave)){
$file = fopen("$dirname"."$dave","r");
fgets($file);
while($row = fgetcsv($file)){
$value = $row[$rows].',';
echo $value;
}
fclose($file);
}}}}
?>
第二個PHP(chart.php)
<?
// 引用相關類別檔
include("pchart/class/pDraw.class.php");
include("pchart/class/pImage.class.php");
include("pchart/class/pData.class.php");
include("value.php");
$myData = new pData();
$myData->addPoints(array($value));
$myPicture = new pImage(800,300,$myData);
$myPicture->setFontProperties(array("FontName"=>"pchart/fonts/calibri.ttf","FontSize"=>10));
$myPicture->setGraphArea(60,40,760,280);
$myPicture->drawScale();
$myPicture->drawlineChart();
$myPicture->render('example_01.png');
$myPicture->autoOutput();
?>
單獨執行value.php可以秀出csv的值(0.0156,-0.0457,-0.0158,-0.1944,-0.5211,-0.4318,-0.0251,-0.1195,-0.6572,-0.2845,-0.5612,-0.8812,)
若將value.php的值帶入chart.php,$value卻僅剩-0.8812
該怎麼那value.php的值,全部帶入chart.php內呢
1,2,3,4 --> 用陣列
我將value.php $value1字串存成陣列
$value1 = $row[$rows];
$value = explode(',',$value1);
仍在chart.php無法正常帶入$value值
while($row = fgetcsv($file)){
$value = $row[$rows].',';
echo $value;
}
把實際的值代入
你寫的實際上是這樣
$value = 0.0156,
echo $value;
$value = -0.0457,
echo $value;
$value = -0.0158,
echo $value;
$value = -0.1944,
echo $value;
$value = -0.5211,
echo $value;
$value = -0.4318,
echo $value;
$value = -0.0251,
echo $value;
$value = -0.1195,
echo $value;
$value = -0.6572,
echo $value;
$value = -0.2845,
echo $value;
$value = -0.5612,
echo $value;
$value = -0.8812,
echo $value;
你只是把不同的值塞入 $value 這個變數
所以 $value 只會保留最後一個值 -0.8812
有兩個改法:
1.用陣列的寫法 array_push($arr, $row[$rows])
2.改成 $value = $value . $row[$rows].',';
傳過去之後再 $arr = explode(",", $value);
$arr 就會是你要的結果
感謝!我使用了第二種方式
沒有代碼不知道你發生什麼事。
一般將兩個php共用的寫法如下
a.php
do{
include(b.php);
}while(1);
以上的寫法就是將b.php做為a.php的一段程式碼。
其運行其實都在a。b變成單純的程式碼共用。
至於你說只有4的問題。推測變數問題了吧。等你有放程式碼再查了。
現在沒辦法。
0不是只會跑一次。我是要讓他無限。
哇哈哈
不過好像會被擋下來的樣子。
那來個薛丁格的 while?while(random_int(0, 1));
我的CSV檔(ABC_200522.CSV)
time,DEF,ABC
01:01:00,-0.0153,0.0156
00:00:01,-0.0153,-0.0457
00:00:02,-0.0353,-0.0158
00:00:03,-0.0353,-0.1944
00:00:04,-0.0353,-0.5211
00:00:05,-0.0353,-0.4318
00:00:06,-0.0353,-0.0251
00:00:07,-0.0353,-0.1195
00:00:08,-0.0353,-0.6572
00:00:09,-0.0353,-0.2845
00:00:10,-0.0353,-0.5612
00:00:11,-0.0353,-0.8812
第一個PHP(value.php)
<?php
$dirname="pchart/csv/";
$dh=opendir($dirname);
$keyword = ABC;
$date = 200522;
$rows = 2;
while ($dave=readdir($dh))
{
if ($dave != "." && $dave != "..") {
if (preg_match("/$keyword/i",$dave)){
if (preg_match("/$date/i",$dave)){
$file = fopen("$dirname"."$dave","r");
fgets($file);
while($row = fgetcsv($file)){
$value = $row[$rows].',';
echo $value;
}
fclose($file);
}}}}
?>
第二個PHP(chart.php)
<?
// 引用相關類別檔
include("pchart/class/pDraw.class.php");
include("pchart/class/pImage.class.php");
include("pchart/class/pData.class.php");
include("value.php");
$myData = new pData();
$myData->addPoints(array($value));
$myPicture = new pImage(800,300,$myData);
$myPicture->setFontProperties(array("FontName"=>"pchart/fonts/calibri.ttf","FontSize"=>10));
$myPicture->setGraphArea(60,40,760,280);
$myPicture->drawScale();
$myPicture->drawlineChart();
$myPicture->render('example_01.png');
$myPicture->autoOutput();
?>
單獨執行value.php可以秀出csv的值(0.0156,-0.0457,-0.0158,-0.1944,-0.5211,-0.4318,-0.0251,-0.1195,-0.6572,-0.2845,-0.5612,-0.8812,)
若將value.php的值帶入chart.php,$value卻僅剩-0.8812
該怎麼那value.php的值,全部帶入chart.php內呢