วันศุกร์ที่ 26 เมษายน พ.ศ. 2562

PHP สร้าง Text File // อ่าน Text File

การสร้าง Text File
<?php
$myfile = fopen("sk_fore.txt", "w") or die("Unable to open file!");
$txt = number_format($row_rs_eff2for[forebay],2);
fwrite($myfile, $txt);
$txt = "|".$row_rs_eff2for[eff_storage];
fwrite($myfile, $txt);
$txt = "|".$row_rs_eff2for_ncc[forebay];
fwrite($myfile, $txt);
$txt = "|".$row_rs_eff2for_ncc[eff_storage];
fwrite($myfile, $txt);


fclose($myfile);
?> 


การอ่าน Text File

    <?php
            $myFile = "../../sk/sk_fore.txt";
            $fh = fopen($myFile, 'r');
            $theData = explode("|",fread($fh, filesize($myFile)));
            fclose($fh);
        ?>


นำไปแสดงผล
    <tr>
        <td colspan="3" rowspan="3" background="images/sk_graphic4_65.gif"><input name="textfield" type="text" class="style11" value="<?=number_format($theData[1],2);?>"  size="8" maxlength="10"> </td>

PHP การบวกเพิ่มค่าแบบทวีคูณ โดย Dreamweaver


mysql_select_db($database_sk50, $sk50);
$query_rs_inf_rel = "SELECT    plan_ncc_data.mydate as r_date,   plan_ncc_data.inflow_ncc as inflow_ncc,   plan_ncc_data.release_ncc as release24,   plan_ncc_data.inflow_61 as inflow24 FROM   xxxxx WHERE   plan_ncc_data.mydate BETWEEN  '$input1' AND '$input2'";
$rs_inf_rel = mysql_query($query_rs_inf_rel, $sk50) or die(mysql_error());
$row_rs_inf_rel = mysql_fetch_assoc($rs_inf_rel);
$totalRows_rs_inf_rel = mysql_num_rows($rs_inf_rel);


   $sumdiff= $row_show_eff['eff_now'];
  do { 
       $wdiff = $row_rs_inf_rel['inflow24'] - $row_rs_inf_rel['release24'];
       $wdiff_ncc = $row_rs_inf_rel['inflow_ncc'] - $row_rs_inf_rel['release24'];
       $sumdiff =$sumdiff  +$wdiff ;  //บวกเพิ่มค่าตัวที่ 1
       $sumdiff1 =$sumdiff  +$wdiff_ncc ; //บวกเพิ่มค่าตัวที่ 2
    

// กำหนดเก็บข้อมูลในรูปแบบ array
        $mydt[] = $row_rs_inf_rel['r_date'];
        $inflow_24[] = $row_rs_inf_rel['inflow24'];
        $release_24[] = $row_rs_inf_rel['release24'];
        $inflow_ncc[] =  $row_rs_inf_rel['inflow_ncc'];
        $wdiff_24[]=$wdiff;
        $wdiff_ncc1[]=$wdiff_ncc;
        $sumdiff_24[] = $sumdiff;
        $sumdiff_ncc[] = $sumdiff1;
   
 } while ($row_rs_inf_rel = mysql_fetch_assoc($rs_inf_rel));