|
|
|
การใช้ฟังก์ชั่นผ่านลูป for เราใช้function ในลูปforไม่ได้หลอคะลองรันแล้วเหมือนมันเข้าไปทำให้แค่ลูปแรก |
|
|
|
|
|
|
|
เราใช้function ในลูปforไม่ได้หลอคะ
ลองรันแล้วเหมือนมันเข้าไปทำให้แค่ลูปแรก
Code (PHP)
function ReadData($x1,$date)
{
$strPathName = "H:/pp/ThaiCom/TH/" ;
$strFile = $strPathName.$x1 ;
if(file_exists($strFile)){
//echo "Have file<br/>";
$objFopen = fopen($strFile, 'r');
while (!feof($objFopen))
{
$file = fgets($objFopen);
$TMsel=trim($file);
$compare = substr($TMsel,0,5);
$value = trim(substr($TMsel,strpos($TMsel," ")));
$t[]="";
$t[0]=$date;
switch ($compare)
{
case "T007K": echo $compare.$value."<br>"; $t["1"] = $value; break;
Case "T008K": echo $compare.$value."<br>"; $t["2"] = $value; break;
Case "T009K": echo $compare.$value."<br>"; $t["3"] = $value; break;
Case "T010K": echo $compare.$value."<br>"; $t["4"] = $value; break;
Case "T011K": echo $compare.$value."<br>"; $t["5"] = $value; break;
Case "T012K": echo $compare.$value."<br>"; $t["6"] = $value; break;
Case "T013K": echo $compare.$value."<br>"; $t["7"] = $value; break;
Case "T014K": echo $compare.$value."<br>"; $t["8"] = $value; break;
Case "T020K": echo $compare.$value."<br>"; $t["9"] = $value; break;
Case "T021K": echo $compare.$value."<br>"; $t["10"] = $value; break;
Case "T022K": echo $compare.$value."<br>"; $t["11"] = $value; break;
Case "T023K": echo $compare.$value."<br>"; $t["12"] = $value; break;
Case "T024K": echo $compare.$value."<br>"; $t["13"] = $value; break;
Case "T056K": echo $compare.$value."<br>"; $t["14"] = $value; break;
Case "T057K": echo $compare.$value."<br>"; $t["15"] = $value; break;
Case "T058K": echo $compare.$value."<br>"; $t["16"] = $value; break;
}
}
fclose($objFopen);
}
return $t;
}
$objConnect = odbc_connect("mydatabase","","") or die("Error Connect to Database");
$strSQL = "SELECT Max(Time) as LastestTime FROM Thermal ";
$objExec = odbc_exec($objConnect, $strSQL) or die ("Error Execute [".$strSQL."]");
while(odbc_fetch_row($objExec))
{
$LastRecord = odbc_result($objExec,"LastestTime") ;
}
odbc_close($objConnect);
$year = substr($LastRecord,0,4);
$month = substr($LastRecord,5,2);
$day = substr($LastRecord,8,2);
$hour= substr($LastRecord,-8,2)+1;
echo $hour;
for($m=$month;$m <= 12; $m++){
for ($d=$day;$d <= 31; $d++){
for($h=$hour;$h<=23;$h++){
if (strlen($m)== 1){$m ="0".$m ;}
if (strlen($d)== 1){$d ="0".$d ;}
if (strlen($h)== 1){$h ="0".$h ;}
$nextRecord = $year.$m.$d."_" . $h."_00.txt" ;
echo"$nextRecord</br>";
$StampD = $d."/".$m."/".$year." ".$h.":00";
$Data="";
$Data= ReadData($nextRecord,$StampD) ;
echo"result is</br>" ;
foreach($Data as $NRecord){
print $NRecord."</br>";
}
//$objConnect2 = odbc_connect("mydatabase","","") or die("Error Connect to Database");
//$strSQL2 = "INSERT into Thermal values('$data[0]','$data[1]','$data[2]')";
//$objExec2 = odbc_exec($objConnect2, $strSQL2) or die ("Error Execute [".$strSQL2."]");
//odbc_close($objConnect2);
}$hour=0;
}$day=1;
} $month=1;
Tag : - - - -
|
|
|
|
|
|
Date :
2010-05-18 14:34:08 |
By :
S-t-A-r |
View :
696 |
Reply :
0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|