วันพฤหัสบดีที่ 8 พฤษภาคม พ.ศ. 2557

Jquery บวก ลบ ค่า Input text 2 ช่องอัตโนมัติ

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> Plus Value</title>
<script type='text/javascript' src='//code.jquery.com/jquery-1.11.0.js'></script>
<link rel="stylesheet" type="text/css" href="/css/normalize.css">
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
<style type='text/css'>
</style>
<script type='text/javascript'>
$(function() {
    var output_element = $('#output_ele');
    var output_element1 = $('#output_ele1');

    $('#the_input_id').keyup(function() {  
        updateTotal();
    });
    
    $('#the_input_id1').keyup(function() {  
        updateTotal();
    });
    
    var updateTotal = function () {
      var input1 = parseInt($('#the_input_id').val());
      var input2 = parseInt($('#the_input_id1').val());
       var totals = parseFloat(input1 + input2) || 0;
       //parseFloat($('#totals').val()) || 0; 
      $('#total').text(totals);
    };

  // output_total.text(total);

 });
</script>
</head>
<body>
<form method="post">
<input type="text" id="the_input_id">
<input type="text" id="the_input_id1">
</form>
<div id="total">

</div>
</body>


</html>


ตัวอย่าง

วันอังคารที่ 6 พฤษภาคม พ.ศ. 2557

รวม php for Dreamweaver code ใช้งาน

1. กำหนด เพิ่ม - ลด วัน

$mydate = @$_GET['dates'];
if ($mydate == ""){
$mydates =  $row_rs_check_last['dates'];
$mydates1 =  date("Y-m-d", strtotime("-1 day", strtotime($mydates))); //ลดวัน 1 วัน

} else {
$mydates =  $mydate;
$mydates1 =  date("Y-m-d", strtotime("1 day", strtotime($mydates))); // เพิ่มวัน 1 วัน

}

2.  Dreamweaver ส่งค่าจาก Insert - Update แล้ว Go to  เมื่อ Post Form แล้วค่าตัวแปรจะค้างไว้
ถ้าไม่ต้องการใช้งานให้ ต้องปิดส่วนที่โปรแกรมทำไว้ ****



if (@$_POST['dates1'] =="") {
$chkdate = "";
} else {
$chkdate = @$_POST['dates1'];
}

  $updateGoTo = "myindex.php?dates=" .$chkdate. "&chk=2"; // ส่งค่าไปพร้อมกัน
  /* *** ส่วนนี้เป็นการปิดค่าที่ โปรแกรม Dreamweaver จะแสดงด้วยจาก Form
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  } */
  header(sprintf("Location: %s", $updateGoTo));
}

3. กำหนดการแสดงผลเอง แทน Dreamweaver
 3.1 Dream ทำให้
 <?php do {   // เริ่ม Loop แสดงผลของ Dream
// ทำสีบรรทัด
     if ($row_rs_report['times'] == 1 || $row_rs_report['times'] == 8 || $row_rs_report['times'] == 16 || $row_rs_report['times'] == 24) {
 $cl = "#FF9999";
 } else {
 $cl = "#FFFFFF";
 }
 // จบทำสีบรรทัด
 ?>
    <tr bgcolor="<?php echo $cl; ?>">
    <td><a href="myindex.php?ids=<?php echo $row_rs_report['ids']; ?>&amp;edit=1&amp;times=<?php echo $row_rs_report['times']; ?>&amp;dates=<?php echo $row_rs_report['dates']; ?>"><?php echo $row_rs_report['times']; ?>:00</a></td>
    <td><?php echo $row_rs_report['read_180']; ?></td>
    <td><?php echo $row_rs_report['egat_waterflow']; ?></td>
    <td><?php echo $row_rs_report['power_hour']; ?></td>
    <td><?php echo $row_rs_report['gen_sync']; ?></td>
    <td><?php echo $row_rs_report['gen_open']; ?></td>
    <td><?php echo $row_rs_report['time_sync']; ?></td>
    <td><?php echo $row_rs_report['name']; ?></td>
  </tr>
    <?php } while ($row_rs_report = mysql_fetch_assoc($rs_report));
    // สิ้นสุด Loop แสดงผลของ Dream  ?>

3.2 กำหนดเอง 
<?php

  @$ender = round($totalRows_rs_chon -1);
    do {   // เริ่ม Loop แสดงผลเอง
         //** แทน Array จากที่ที่ต้องการ
$dates [] =$row_rs_chon['dates'];
$times[] = $row_rs_chon['times'];
$waterflow[] = $row_rs_chon['egat_waterflow'];
$waterdiff[] =  $row_rs_chon['diff'];

$st = round(@$waterflow[0]);    // กำหนดเลือกเอาบางค่าที่ต้องการ
$et = round(@$waterflow[@$ender]);
 } while ($row_rs_chon = mysql_fetch_assoc($rs_chon));
    // สิ้นสุด Loop แสดงผลขเอง ?>


          นำไปแสดงผลเอง

<?php for ($i=1;$i < $totalRows_rs_chon;$i++) { ?> // กำหนดเริ่มที่ 0 ถ้าต้องการเริ่มที่ Row อื่นกำหนดที่ $i
  <tr bgcolor="#99ff99">
    <td align="center"><?php echo $dates[$i]; ?>&nbsp;</td>
    <td align="center"><?php echo digi($times[$i]); ?> </td>
    <td align="center"><?php echo digi($waterflow[$i]); ?></td>
    <td align="right"><?php echo digi($waterdiff[$i]); ?></td>
  </tr>

  <?php } ?>


CSS กำหนด Div ให้เป็นแบบ สี่เหลี่ยมมุมมน border-radius

<style>
.mydiv
{
text-align:center;
color:#F00000;
border:2px solid #00F000;
border-radius:25px;
width:50%;
margin:auto;
}
</style>

//การใช้งาน
<div class="mydiv">
    <h1> ยินดีต้อนรับเข้าสู่โรงไฟฟ้าเขื่อนนเรศวร </h1><br />
<br />
<h2> ข้อมูลน้ำระบายผ่านเครื่องกำเนิดไฟฟ้า <?php
    $dt1=strtotime($row_rs_report['dates']); echo thai_date($dt1); ?>
</h2>
    </div>


// sample ผลลัพธ์


php แปลง วันเดือนปี เป็นแบบวันที่ไทย & number format

<?php
// กำหนดการแสดงผลตัวเลข number format
function digi2($num1){
$num = number_format($num1,2);
return $num;
}
function digi($num2){
$num3 = number_format($num2);
return $num3;
}

// แปลงวันที่แบบสากล เป็นแบบไทย
$thai_day_arr=array("อาทิตย์","จันทร์","อังคาร","พุธ","พฤหัสบดี","ศุกร์","เสาร์");
$thai_month_arr=array(
"0"=>"",
"1"=>"มกราคม",
"2"=>"กุมภาพันธ์",
"3"=>"มีนาคม",
"4"=>"เมษายน",
"5"=>"พฤษภาคม",
"6"=>"มิถุนายน",
"7"=>"กรกฎาคม",
"8"=>"สิงหาคม",
"9"=>"กันยายน",
"10"=>"ตุลาคม",
"11"=>"พฤศจิกายน",
"12"=>"ธันวาคม"
);
function thai_date($time){
global $thai_day_arr,$thai_month_arr;
//$thai_date_return="วัน".$thai_day_arr[date("w",$time)];
$thai_date_return = date("j",$time);
$thai_date_return.= " ".$thai_month_arr[date("n",$time)];
$thai_date_return.= " ".(date("Y",$time)+543);
//$thai_date_return.= "  ".date("H:i",$time)." น.";
return $thai_date_return;
}
function thai_sdate($time){
global $thai_day_arr,$thai_month_arr;
//$thai_sdate_return="วัน".$thai_day_arr[date("w",$time)];
$thai_sdate_return = date("j",$time);
$thai_sdate_return.= " ".$thai_month_arr[date("n",$time)];
//$thai_date_return.= " พ.ศ.".(date("Y",$time)+543);
//$thai_date_return.= "  ".date("H:i",$time)." น.";
return $thai_sdate_return;
}

// การใช้งาน
  $dt1=strtotime($row_rs_report['dates']);  //กำหนดตัวแปล
   echo thai_date($dt1); //การแสดงผล

?>

php แปลง นาที ฐานร้อย เป็น ชั่วโมง เวลา Function to convert minutes to hours


<?php
function m2h($mins) {
    if ($mins < 0) {
        $min = Abs($mins);
    } else {
        $min = $mins;
    }
    $H = Floor($min / 60);
    $M = ($min - ($H * 60)) / 100;
    $hours = $H + $M;
    if ($mins < 0) {
        $hours = $hours * (-1);
    }

    $expl = explode(".", $hours);
    $H = $expl[0];
    if (empty($expl[1])) {
        $expl[1] = 00;
    }

    $M = $expl[1];
    if (strlen($M) < 2) {
        $M = $M . 0;
    }

    $hours = $H . "." . $M;

    return $hours;
}
?>