|
|
|
สอบถามครับ ตอนนี้ sum ข้อมูลใน textbox ได้แล้วแต่ติดปัญหาเวลาวนลูปแล้ว script sum ไม่ทำงานครับรบกวนผู้รู้ช่วยหน่อยครับ |
|
|
|
|
|
|
|
Code (PHP)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<HEAD>
<TITLE> New Document </TITLE>
<SCRIPT Language="JavaScript">
function startCalc(){
interval = setInterval("calc()",1);
}
function calc(){
a = document.autoSumForm.p_electric1.value;
b = document.autoSumForm.p_electric2.value;
document.autoSumForm.p_total_electric.value = (b * 1) - (a * 1);
c = document.autoSumForm.p_total_electric.value;
d = document.autoSumForm.p_unit_electric.value;
document.autoSumForm.p_amount_electric.value = (d * 1) * (c * 1);
e = document.autoSumForm.p_water1.value;
f = document.autoSumForm.p_water2.value;
document.autoSumForm.p_total_water.value = (f * 1) - (e * 1);
g = document.autoSumForm.p_total_water.value;
h = document.autoSumForm.p_unit_water.value;
document.autoSumForm.p_amount_water.value = (h * 1) * (g * 1);
qty1 = document.autoSumForm.p_amount_electric.value;
qty2 = document.autoSumForm.p_amount_water.value;
m_price = document.autoSumForm.m_price.value;
document.autoSumForm.p_qty.value = (qty2 * 1) + (qty1 * 1) + (m_price * 1);
}
function stopCalc(){
clearInterval(interval);
}
</SCRIPT>
</HEAD>
<BODY>
<?php
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("hotel");
//*** Update Condition ***//
if($_GET["Action"] == "Save")
{
for($i=1;$i<=$_POST["hdnLine"];$i++)
{
$strSQL = "UPDATE phpversion SET ";
$strSQL .="m_id = '".$_POST["m_id$i"]."' ";
$strSQL .=",m_type_name = '".$_POST["m_room$i"]."' ";
$strSQL .=",m_building = '".$_POST["m_building$i"]."' ";
$strSQL .=",m_floor = '".$_POST["m_floor$i"]."' ";
$strSQL .=",m_name = '".$_POST["m_name$i"]."' ";
$strSQL .=",m_id_card = '".$_POST["m_id_card$i"]."' ";
$strSQL .=",m_id_passport = '".$_POST["m_id_passport$i"]."' ";
$strSQL .=",p_datestart = '".$_POST["p_datestart$i"]."' ";
$strSQL .=",p_electric1= '".$_POST["p_electric1$i"]."' ";
$strSQL .=",p_electric2 = '".$_POST["p_electric2$i"]."' ";
$strSQL .=",p_total_electric = '".$_POST["p_total_electric$i"]."' ";
$strSQL .=",p_unit_electric = '".$_POST["p_unit_electric$i"]."' ";
$strSQL .=",p_amount_mitter = '".$_POST["p_amount_mitter$i"]."' ";
$strSQL .=",p_water= '".$_POST["p_water$i"]."' ";
$strSQL .=",p_water2 = '".$_POST["p_water2$i"]."' ";
$strSQL .=",p_total_weter = '".$_POST["p_total_weter$i"]."' ";
$strSQL .=",p_unit_water = '".$_POST["p_unit_water$i"]."' ";
$strSQL .=",p_amount_water = '".$_POST["p_amount_water$i"]."' ";
$strSQL .=",p_qty = '".$_POST["p_qty$i"]."' ";
$strSQL .=",p_save = '".$_POST["p_save$i"]."' ";
$strSQL .="WHERE m_id = '".$_POST["hdnm_id$i"]."' ";
$objQuery = mysql_query($strSQL);
$strSQL2 = "INSERT INTO total_qty2 ";
$strSQL2 .="(p_room,p_price,p_building,p_floor,m_name,m_id_card,m_id_passportp_datestart,p_electric1,p_electric2,p_total_electric,p_unit_electric,p_amount_electricp_water1,p_water2,p_total_water,p_unit_water,p_amount_water,p_qty,p_save) ";
$strSQL2 .="VALUES ";
$strSQL2 .="('".$_POST["p_room"]."','".$_POST["p_price"]."','".$_POST["p_building"]."','".$_POST["p_floor"]."','".$_POST["m_name"]."','".$_POST["m_id_card"]."','".$_POST["m_id_passport"]."','".$_POST["p_datestart"]."','".$_POST["p_electric1"]."','".$_POST["p_electric2"]."','".$_POST["p_total_electric"]."','".$_POST["p_uint_electric"]."' ";
$strSQL2 .=",'".$_POST["p_amount_electric"]."','".$_POST["p_water1"]."','".$_POST["p_water2"]."','".$_POST["p_total_water"]."','".$_POST["p_unit_water"]."','".$_POST["p_amount_water"]."','".$_POST["p_qty"]."','".$_POST["p_save"]."')";
$objQuery2 = mysql_query($strSQL) or die ("Error in query[".$strSQL."]");
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
$strSQL = "SELECT * FROM playment WHERE MONTH(p_datestart) BETWEEN MONTH(now())-1 AND MONTH(now()) ORDER BY m_id ASC";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<div style="width: 200px; text-align: center;">
<form name="autoSumForm" method="post" action="add2.php?Action=Save">
<table width="1000" border="1" >
<tr>
</tr>
<tr>
<?php
$i =0;
while($objResult = mysql_fetch_array($objQuery))
{
$i = $i + 1;
?>
<tr>
<td>
<input type="hidden" name="hdnm_id<?php echo $i;?>" size="5" value="<?php echo $objResult["m_id"];?>">
<input type="hidden" name="m_id<?php echo $i;?>" size="5" value="<?php echo $objResult["m_id"];?>" readonly>
<input type="text" name="m_room<?php echo $i;?>" size="5" value="<?php echo $objResult["m_type_name"];?>" readonly></td>
<td>
<input class="right" type=text name="m_price" size="5" value="3000" onFocus="startCalc();" onBlur="stopCalc();"></td>
<td>
<input type="text" name="m_building<?php echo $i;?>" size="5" value="<?php echo $objResult["m_building"];?>" readonly ></td>
<td>
<input type="text" name="m_floor<?php echo $i;?>" size="5" value="<?php echo $objResult["m_floor"];?>" readonly></td>
<td>
<input type="text" name="p_datestart<?php echo $i;?>" size="5" value="<?php echo $objResult["p_datestart"];?>" readonly></td>
<td>
<input class="right" type=text name="p_electric1<?php echo $i;?>" size="5" value="200" onFocus="startCalc();" onBlur="stopCalc();">
</td>
<td>
<input class="right" type=text name="p_electric2<?php echo $i;?>" size="5" value="" onFocus="startCalc();" onBlur="stopCalc();">
</td>
<td>
<input class="right" type=text name="p_total_electric<?php echo $i;?>" size="5" value="" onFocus="startCalc();" onBlur="stopCalc();">
</td>
<td>
<input class="right" type=text name="p_unit_electric<?php echo $i;?>" size="5" value="5" onFocus="startCalc();" onBlur="stopCalc();">
</td>
<td>
<input class="right" type=text name="p_amount_electric<?php echo $i;?>" size="5" value="" onFocus="startCalc();" onBlur="stopCalc();">
</td>
<td>
<input class="right" type=text name="p_water1" size="5" value="200" onFocus="startCalc();" onBlur="stopCalc();">
</td>
<td>
<input class="right" type=text name="p_water2" size="5" value="" onFocus="startCalc();" onBlur="stopCalc();">
</td>
<td>
<input class="right" type=text name="p_total_water" size="5" value="" onFocus="startCalc();" onBlur="stopCalc();">
</td>
<td>
<input class="right" type=text name="p_unit_water" size="5" value="15" onFocus="startCalc();" onBlur="stopCalc();" >
</td>
<td>
<input class="right" type=text name="p_amount_water" size="5" value="" onFocus="startCalc();" onBlur="stopCalc();">
</td>
<td>
<input class="right" type=text name="p_qty" size="5" >
</td>
</tr>
<?php
}
?>
</table>
</form>
<?php
mysql_close($objConnect);
?>
</div>
</BODY>
</HTML>
Tag : PHP, MySQL, JavaScript
|
|
|
|
|
|
Date :
2018-10-15 16:20:43 |
By :
Lun2560 |
View :
596 |
Reply :
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
น่าจะมี Error ครับ ถ้าใช้บน Chrome ลองดู Console หรือกด Ctrl+Shift+J
|
|
|
|
|
Date :
2018-10-17 14:53:34 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
หรือว่าผมนำโค้ดมาใช้งานผิดรูปแบบครับ
ถ้าไม่ได้วนลูป
แต่ถ้าวนลูป
|
ประวัติการแก้ไข 2018-10-18 09:35:49
|
|
|
|
Date :
2018-10-18 09:33:05 |
By :
Lun2560 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
งั้นส่วนนี้คงต้องรอท่านที่รู้มาช่วยตอบ ตอนนี้ผมใช้วิธีการให้อัพเดททีละไอดีไปก่อน เพราะดึงทีละไอดี script ทำงานปกติ
|
|
|
|
|
Date :
2018-10-18 14:51:05 |
By :
Lun2560 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
รบกวนอีกนิดครับ อัพเดทไม่ผ่าน
Code (PHP)
<DOCTYPE thml>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="Marosdee" />
<script type="text/javascript">
function calculate(count)
{
var qty = 0;
var wrench1 = parseInt(document.getElementById('wrench1' + count).value);
var wrench2 = parseInt(document.getElementById('wrench2' + count).value);
var unit = parseInt(document.getElementById('unit' + count).value);
var vat = parseInt(document.getElementById('vat' + count).value);
if ( isNaN(wrench1) )
{
wrench1 = 0;
}
if ( isNaN(wrench2) )
{
wrench2 = 0;
}
if ( isNaN(unit) )
{
unit = 0;
}
if ( isNaN(vat) )
{
vat = 0;
}
qty = (wrench2 - wrench1) * unit + vat;
document.getElementById('qty' + count).value = qty;
}
</script>
<title>Untitled 5</title>
</head>
<body>
<?php
include('condb.ua.php');
//*** Update Condition ***//
if($_GET["Action"] == "Save")
{
for($i=1;$i<=$_POST["hdnLine"];$i++)
{
/*
echo "<pre>";
print_r($_POST);
echo "</pre>";
exit();
*/
$strSQL = "UPDATE count SET ";
$strSQL .="id = '".$_POST["id$i"]."' ";
$strSQL .=",wrench1 = '".$_POST["wrench1$i"]."' ";
$strSQL .=",wrench2 = '".$_POST["wrench2$i"]."' ";
$strSQL .=",unit = '".$_POST["unit$i"]."' ";
$strSQL .=",vat = '".$_POST["vat$i"]."' ";
$strSQL .=",qty = '".$_POST["qty$i"]."' ";
$strSQL .="WHERE id = '".$_POST["hdnid$i"]."' ";
$objQuery = mysql_query($strSQL);
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
$strSQL = "SELECT * FROM count ORDER BY id ASC";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<form method="post" action="10.php?Action=Save" id="form<?php echo $i ?>" name="form<?php echo $i ?>">
<table width="800" border="1">
<tr>
<td>ยอดก่อหน้า</td>
<td>ยอดปัจจุบัน</td>
<td>หน่วย</td>
<td>อื่นๆ </td>
<td>รวม </td>
</tr>
<?php
$i = 0;
while($objResult = mysql_fetch_assoc($objQuery))
{
$i = $i + 1;
?>
<tr>
<td><input type="text" name="wrench1" id="wrench1<?php echo $i ?>" onkeyup="calculate(<?php echo $i ?>)" value="<?php echo $objResult["wrench1"];?>" />
</td>
<td><input type="text" name="wrench2" id="wrench2<?php echo $i ?>" onkeyup="calculate(<?php echo $i ?>)" value="" />
</td>
<td><input type="text" name="unit" id="unit<?php echo $i ?>" onkeyup="calculate(<?php echo $i ?>)" value="<?php echo $objResult["unit"];?>" />
</td>
<td><input type="text" name="vat" id="vat<?php echo $i ?>" onkeyup="calculate(<?php echo $i ?>)" value="<?php echo $objResult["vat"];?>" />
</td>
<td><input type="text" name="qty" id="qty<?php echo $i ?>" />
</td>
<?php
$i++;
}
?>
<table>
<input type="submit" name="submit" value="submit">
<input type="hidden" name="hdnLine" value="<?php echo $i;?>">
</form>
<?php
mysql_close($objConnect);
?>
</body>
</html>
|
|
|
|
|
Date :
2018-10-18 17:04:43 |
By :
Lun2560 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ดูดีๆคับว่าอะไรผิด เปรียบเทียบโค้ดกับตัวอย่างในเว็บก็มีนะคับ
ลองแก้ดูจะได้เข้าใจด้วย สู้ๆคับ
|
|
|
|
|
Date :
2018-10-19 12:30:21 |
By :
HLEW |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|