2017-06-16 95 views
0

如何使用total_no_of_units和cost_per_unit中total_cost_acquistion中输入的值即(总成本=单位*每单位成本),建议我以任何方式执行此操作.. total_cost_acquistion的值必须为只要no_of_units和cost_per_units给出displaye ....从表格中提取值

<?php 
    require_once "session.php"; 
?> 
<?php 
    include('connection.php'); 
    if (isset($_POST['submit'])){ 
     $sl_no =$_POST['sl_no']; 
     $dec =$_POST['description']; 
     $loctn =$_POST['location']; 
     $ref_no =$_POST['reference_no']; 
     $d_of_aqstn =$_POST['date_of_acquisation']; 
     $t_of_un =$_POST['total_no_of_units']; 
     $cst_p_un =$_POST['cost_per_unit']; 
     $tl_cost_aqstn =$_POST['total_cost_of_acquistion']; 
     $lf_ast_pr_cdl =$_POST['life_of_assets_per_codal']; 
     $no_yr_ast_use =$_POST['no_year_assets_use']; 
     $rt_deprtn =$_POST['rate_depreciation']; 
     $act_deprtn =$_POST['accumulate_depreciation']; 
     $val_as_on = $_POST['value_as_on']; 
     $remks =$_POST['remarks']; 

     $query = "insert into form(sl_no, description, location, reference_no, date_of_acquisation, total_no_of_units, cost_per_unit, total_cost_of_acquistion, life_of_assets_per_codal, no_year_assets_use, rate_depreciation, accumulate_depreciation, value_as_on, remarks) 
    values('$sl_no','$dec','$loctn','$ref_no','$d_of_aqstn','$t_of_un','$cst_p_un','$tl_cost_aqstn','$lf_ast_pr_cdl','$no_yr_ast_use','$rt_deprtn','$act_deprtn','$val_as_on','$remks')"; 
    $retval = mysql_query($query,$con); 
    if(!$retval) 
     { 
     die('Could not enter data: ' . mysql_error()); 
     } 
    mysql_close($con); 
    } 
    ?> 
    <html> 
    <head> 
     <meta charset = "utf-8"> 
     <link rel = "stylesheet" 
      href = "//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> 

     <script type = "text/javascript" 
      src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 

     <script type = "text/javascript" 
      src = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script> 

     <script> 
      $(function() { 
       $("#datepicker").datepicker(); 
      }); 
     </script> 
     <title>Add a Form</title> 
    </head> 
     <body> 
    <h1 align="center"><strong>FIXED ASSET REGISTER</strong></h1> 
    <b align="center">Welcome : <i><?php echo $_SESSION['login_user']; ?> </i></b> 
     <br> 

     <form method="POST" action="<?php $PHP_SELF ?>"> 
     <div align="center"> 
      <table width=100% cellpadding="5" cellspacing="2" align="center"> 
       <tr> 
       <td colspan="2" align="center"> <h2><strong>FORM-10</strong></h2></td> 
       </tr> 
       <tr> 
       <td align="right"> <strong>Serial_No:</strong></td> 
       <td><input type="text" name="sl_no" placeholder="Serial_no" required></td> 
       </tr> 

       <tr> 
       <td align="right"> <strong>Description :</strong></td> 
       <td><input type="text" name="description" placeholder="description" required></td> 
       </tr> 
       <tr> 
       <td align="right"> <strong>Location:</strong></td> 
       <td><input type="text" name="location" placeholder="location" required></td> 
       </tr> 
       <tr> 
       <td align="right"> <strong>Reference_no:</strong></td> 
       <td><input type="text" name="reference_no" placeholder="reference_no" required></td> 
       </tr> 

      <tr> 
       <td align="right"> <strong>Date_of_Acquisition:</strong></td> 
       <td><input type="text" name="date_of_acquisation" id = "datepicker" placeholder="date_of_acquisation" required></td> 
       </tr> 

       <tr> 

       <td align="right"> <strong>Total_no_of_Units:</strong></td> 
       <td><input type="text" name="total_no_of_units" placeholder="total_no_of_units" required></td> 

       </tr> 

       <tr> 
       <td align="right"> <strong>Cost per Unit:</strong></td> 
       <td><input type="text" name="cost_per_unit" placeholder="cost_per_unit" required></td> 

       </tr> 

       <tr> 

       <td align="right"> <strong>Total Acquisition Cost:</strong></td> 
       <td><input type="text" name="total_cost_of_acquistion" placeholder="total_cost_of_acquistion" required></td> 


       </tr> 

       <tr> 
         <td align="right"> <strong>Asset Life:</strong></td> 
       <td><input type="text" name="life_of_assets_per_codal" placeholder="life_of_assets_per_codal" required></td> 
       </tr> 

       <tr> 
         <td align="right"> <strong>Years asset used:</strong></td> 
       <td><input type="text" name="no_year_assets_use" placeholder="no_of_year_assets_use" required></td> 
       </tr> 

       <tr> 
         <td align="right"> <strong>Depriciation Rate:</strong></td> 
       <td><input type="text" name="rate_depreciation" placeholder="rate_depreciation" required></td> 
       </tr> 

       <tr> 
         <td align="right"> <strong>Accumulated Depriciation:</strong></td> 
       <td><input type="text" name="accumulate_depreciation" placeholder="accumulate_depreciation_till_31/03/2016" required></td> 
       </tr> 

       <tr> 
         <td align="right"> <strong>Valuation:</strong></td> 
       <td><input type="text" name="value_as_on" placeholder="value_as_on_31/03/2016" required></td> 
       </tr> 

       <tr> 
         <td align="right"> <strong>Remarks:</strong></td> 
       <td><input type="text" name="remarks" placeholder="remarks" ></td> 
     </tr> 




      <!-- <tr> 
       <td align="right"> <strong>Status: </strong></td> 
       <td><select name="status" required> 
        <option></option> 
        <option>New</option> 
        <option>Old</option> 
        <option>Lost</option> 
        <option>Damage</option> 
        <option>Subject for Replacement</option> 
        <option>Archive</option> 
       </select> 
       </td> 
      </tr>--> 
       <tr> 
       <td colspan="2" align="center"><input type='submit' value=' Save ' name='submit'> 

       </tr> 
      </table> 
      <h4 align="right"><a href="mainpage1.php">BACK</a></h4> 
     </div> 
     </form> 

    </body> 
    </html> 
+0

请尝试巩固你的答案。当你发布一段代码时,想弄清楚你想要什么是很困难的。隔离这个问题,它会更容易回答。 – JoshKopen

+0

目前还不清楚你在问我什么......“总成本=单位*成本”有什么问题? – Jeff

+2

这里没有任何信息......只是评论一下这个事实,当编程人员这样做时,我发现它真的很奇怪......?><?php' ...为什么? – Dale

回答

0

我想这是你想要什么:

<?php 
require_once "session.php"; 
?> 
<?php 
include('connection.php'); 
if (isset($_POST['submit'])){ 
$sl_no =$_POST['sl_no']; 
$dec =$_POST['description']; 
$loctn =$_POST['location']; 
$ref_no =$_POST['reference_no']; 
$d_of_aqstn =$_POST['date_of_acquisation']; 
$t_of_un =$_POST['total_no_of_units']; 
$cst_p_un =$_POST['cost_per_unit']; 
$tl_cost_aqstn =$_POST['total_cost_of_acquistion']; 
$lf_ast_pr_cdl =$_POST['life_of_assets_per_codal']; 
$no_yr_ast_use =$_POST['no_year_assets_use']; 
$rt_deprtn =$_POST['rate_depreciation']; 
$act_deprtn =$_POST['accumulate_depreciation']; 
$val_as_on = $_POST['value_as_on']; 
$remks =$_POST['remarks']; 

$query = "insert into form(sl_no, description, location, reference_no, date_of_acquisation, total_no_of_units, cost_per_unit, total_cost_of_acquistion, life_of_assets_per_codal, no_year_assets_use, rate_depreciation, accumulate_depreciation, value_as_on, remarks) 
values('$sl_no','$dec','$loctn','$ref_no','$d_of_aqstn','$t_of_un','$cst_p_un','$tl_cost_aqstn','$lf_ast_pr_cdl','$no_yr_ast_use','$rt_deprtn','$act_deprtn','$val_as_on','$remks')"; 
$retval = mysql_query($query,$con); 
if(!$retval) 
    { 
    die('Could not enter data: ' . mysql_error()); 
    } 
mysql_close($con); 
} 
    ?> 
    <html> 
<head> 
    <meta charset = "utf-8"> 
    <link rel = "stylesheet" 
     href = "//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> 

    <script type = "text/javascript" 
     src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 

    <script type = "text/javascript" 
     src = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script> 

    <script> 
     $(function() { 
      $("#datepicker").datepicker(); 
     }); 
    </script> 
    <title>Add a Form</title> 
</head> 
    <body> 
<h1 align="center"><strong>FIXED ASSET REGISTER</strong></h1> 
<b align="center">Welcome : <i><?php echo $_SESSION['login_user']; ?> </i></b> 
    <br> 

    <form method="POST" action="<?php $PHP_SELF ?>"> 
    <div align="center"> 
     <table width=100% cellpadding="5" cellspacing="2" align="center"> 
      <tr> 
      <td colspan="2" align="center"> <h2><strong>FORM-10</strong></h2></td> 
      </tr> 
      <tr> 
      <td align="right"> <strong>Serial_No:</strong></td> 
      <td><input type="text" name="sl_no" placeholder="Serial_no" required></td> 
      </tr> 

      <tr> 
      <td align="right"> <strong>Description :</strong></td> 
      <td><input type="text" name="description" placeholder="description" required></td> 
      </tr> 
      <tr> 
      <td align="right"> <strong>Location:</strong></td> 
      <td><input type="text" name="location" placeholder="location" required></td> 
      </tr> 
      <tr> 
      <td align="right"> <strong>Reference_no:</strong></td> 
      <td><input type="text" name="reference_no" placeholder="reference_no" required></td> 
      </tr> 

     <tr> 
      <td align="right"> <strong>Date_of_Acquisition:</strong></td> 
      <td><input type="text" name="date_of_acquisation" id = "datepicker" placeholder="date_of_acquisation" required></td> 
      </tr> 

      <tr> 

      <td align="right"> <strong>Total_no_of_Units:</strong></td> 
      <td><input type="text" name="total_no_of_units" id="total_no_of_units" onkeyup="calculate()" placeholder="total_no_of_units" required></td> 

      </tr> 

      <tr> 
      <td align="right"> <strong>Cost per Unit:</strong></td> 
      <td><input type="text" name="cost_per_unit" id="cost_per_unit" onkeyup="calculate()" placeholder="cost_per_unit" required></td> 

      </tr> 

      <tr> 

      <td align="right"> <strong>Total Acquisition Cost:</strong></td> 
      <td><input type="text" name="total_cost_of_acquistion" id="total_cost_of_acquistion" placeholder="total_cost_of_acquistion" required></td> 


      </tr> 

      <tr> 
        <td align="right"> <strong>Asset Life:</strong></td> 
      <td><input type="text" name="life_of_assets_per_codal" placeholder="life_of_assets_per_codal" required></td> 
      </tr> 

      <tr> 
        <td align="right"> <strong>Years asset used:</strong></td> 
      <td><input type="text" name="no_year_assets_use" placeholder="no_of_year_assets_use" required></td> 
      </tr> 

      <tr> 
        <td align="right"> <strong>Depriciation Rate:</strong></td> 
      <td><input type="text" name="rate_depreciation" placeholder="rate_depreciation" required></td> 
      </tr> 

      <tr> 
        <td align="right"> <strong>Accumulated Depriciation:</strong></td> 
      <td><input type="text" name="accumulate_depreciation" placeholder="accumulate_depreciation_till_31/03/2016" required></td> 
      </tr> 

      <tr> 
        <td align="right"> <strong>Valuation:</strong></td> 
      <td><input type="text" name="value_as_on" placeholder="value_as_on_31/03/2016" required></td> 
      </tr> 

      <tr> 
        <td align="right"> <strong>Remarks:</strong></td> 
      <td><input type="text" name="remarks" placeholder="remarks" ></td> 
    </tr> 




     <!-- <tr> 
      <td align="right"> <strong>Status: </strong></td> 
      <td><select name="status" required> 
       <option></option> 
       <option>New</option> 
       <option>Old</option> 
       <option>Lost</option> 
       <option>Damage</option> 
       <option>Subject for Replacement</option> 
       <option>Archive</option> 
      </select> 
      </td> 
     </tr>--> 
      <tr> 
      <td colspan="2" align="center"><input type='submit' value=' Save ' name='submit'> 

      </tr> 
     </table> 
     <h4 align="right"><a href="mainpage1.php">BACK</a></h4> 
    </div> 
    </form> 
<script> 
    function calculate(){ 
     var number = $('#total_no_of_units').val(); 
     var unitCost = $('#cost_per_unit').val(); 
     var totalCost = $('#total_cost_of_acquistion').val(); 
     if(number=='' || unitCost==''){ 
      $('#total_cost_of_acquistion').val('0'); 
      return false; 
     } 
     else{ 
      $('#total_cost_of_acquistion').val(number*unitCost); 
     } 
    } 
</script> 
</body> 
</html> 
+0

表单中只要我输入total_no_of_units和cost_per_unit的值马上就要以total_cost_of_acquistion的形式使用.... thanku ... –

+0

只要给出两个输入o/p立即显示在total_cost_of _acquistion –

+0

@AkhilJaiswal是不是这样做? – Echoes

0

如果你谈论的是现场更新一个字段的值另一个字段发生变化,那么您将不得不使用客户端脚本像Javascript,Node,Jquery等。我建议为所有字段设置一个默认值,这样你就不必检查值是否为空。

<input id='field1' type='text' value='0' /> 
<input id='field2' type='text' value='0' /> 
<input id='answer' type='text' value='0' /> 

<script> 
    $('#field1').on('input', function(e){ 
    $('#answer').val(parseInt($(this).val()) * parseInt($('#field2').val())); 
    }); 
    $('#field2').on('input', function(e){ 
    $('#answer').val(parseInt($(this).val()) * parseInt($('#field1').val())); 
    }); 
</script> 

您可以根据需要分出正确的字段并更改数学,但概念是相同的。

如果您只是在提交数据后进行更改,那么它只是将相应值域中的服务器端代码的值反馈给客户端代码。

我希望这能回答你的问题。

0

您可以使用jquery显示用户事件的total_cost_acquisition。

类似,

$(document).ready(function() { 

    $('[name="cost_per_unit"]').keyup(function() { 
    calculateTotal(); 
    }); 

    $('[name="total_no_of_units"]').keyup(function() { 
    calculateTotal(); 
    }); 
}); 

function calculateTotal(){ 
    var total = ($('[name="cost_per_unit"]').val() * $('[name="total_no_of_units"]').val()); 
    $('[name="total_cost_of_acquistion"]').val(total); 
} 

希望能解决你的问题

0

尝试下面的代码,请注意我在注释行脚本所做的更改:

<?php 
require_once "session.php"; 
?> 
<?php 
include('connection.php'); 
if (isset($_POST['submit'])){ 
$sl_no =$_POST['sl_no']; 
$dec =$_POST['description']; 
$loctn =$_POST['location']; 
$ref_no =$_POST['reference_no']; 
$d_of_aqstn =$_POST['date_of_acquisation']; 
$t_of_un =$_POST['total_no_of_units']; 
$cst_p_un =$_POST['cost_per_unit']; 
$tl_cost_aqstn =$_POST['total_cost_of_acquistion']; 
$lf_ast_pr_cdl =$_POST['life_of_assets_per_codal']; 
$no_yr_ast_use =$_POST['no_year_assets_use']; 
$rt_deprtn =$_POST['rate_depreciation']; 
$act_deprtn =$_POST['accumulate_depreciation']; 
$val_as_on = $_POST['value_as_on']; 
$remks =$_POST['remarks']; 

$query = "insert into form(sl_no, description, location, reference_no, date_of_acquisation, total_no_of_units, cost_per_unit, total_cost_of_acquistion, life_of_assets_per_codal, no_year_assets_use, rate_depreciation, accumulate_depreciation, value_as_on, remarks) 
values('$sl_no','$dec','$loctn','$ref_no','$d_of_aqstn','$t_of_un','$cst_p_un','$tl_cost_aqstn','$lf_ast_pr_cdl','$no_yr_ast_use','$rt_deprtn','$act_deprtn','$val_as_on','$remks')"; 
$retval = mysql_query($query,$con); 
if(!$retval) 
    { 
    die('Could not enter data: ' . mysql_error()); 
    } 
mysql_close($con); 
} 
    ?> 
    <html> 
<head> 
    <meta charset = "utf-8"> 
    <link rel = "stylesheet" 
     href = "//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> 

    <script type = "text/javascript" 
     src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 

    <script type = "text/javascript" 
     src = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script> 

    <script> 
     $(function() { 
      $("#datepicker").datepicker(); 
     }); 
     //Added a Script to Populate the Fields 
     $(document).on('change','#total_no_of_units',function() { 
      var AmountOfUnits = $(this).val(); 
      if($("#cost_per_unit").val() === '') { 
       //If there is no value in cost_per_unit do not calculate a total 
      }//end if 
      else { 
       //cost_per_unit is not empty and we'll calculate a total value 
       var CostPerUnit = $("#cost_per_unit").val(); 
       //Set the value of total_cost_of_acquistion 
       var TotalCost = AmountOfUnits * CostPerUnit; 
       $("#total_cost_of_acquisition").val(TotalCost); 
      }//end else 
     });//end on change 
     $(document).on('change','#cost_per_unit',function() { 
      var CostPerUnit = $(this).val(); 
      if($("#total_no_of_units").val() === '') { 
       //If there is no value in total_no_of_units do not calculate a total 
      }//end if 
      else { 
       //total_no_of_units is not empty and we'll calculate a total value 
       var AmountOfUnits = $("#total_no_of_units").val(); 
       //Set the value of total_cost_of_acquistion 
       var TotalCost = AmountOfUnits * CostPerUnit; 
       $("#total_cost_of_acquisition").val(TotalCost); 
      }//end else 
     });//end on change     
    </script> 
    <title>Add a Form</title> 
</head> 
    <body> 
<h1 align="center"><strong>FIXED ASSET REGISTER</strong></h1> 
<b align="center">Welcome : <i><?php echo $_SESSION['login_user']; ?> </i></b> 
    <br> 

    <form method="POST" action="<?php $PHP_SELF ?>"> 
    <div align="center"> 
     <table width=100% cellpadding="5" cellspacing="2" align="center"> 
      <tr> 
      <td colspan="2" align="center"> <h2><strong>FORM-10</strong></h2></td> 
      </tr> 
      <tr> 
      <td align="right"> <strong>Serial_No:</strong></td> 
      <td><input type="text" name="sl_no" placeholder="Serial_no" required></td> 
      </tr> 

      <tr> 
      <td align="right"> <strong>Description :</strong></td> 
      <td><input type="text" name="description" placeholder="description" required></td> 
      </tr> 
      <tr> 
      <td align="right"> <strong>Location:</strong></td> 
      <td><input type="text" name="location" placeholder="location" required></td> 
      </tr> 
      <tr> 
      <td align="right"> <strong>Reference_no:</strong></td> 
      <td><input type="text" name="reference_no" placeholder="reference_no" required></td> 
      </tr> 

     <tr> 
      <td align="right"> <strong>Date_of_Acquisition:</strong></td> 
      <td><input type="text" name="date_of_acquisation" id = "datepicker" placeholder="date_of_acquisation" required></td> 
      </tr> 

      <tr> 

      <td align="right"> <strong>Total_no_of_Units:</strong></td> 
      <!-- Added an Id to the form element so I can select it with JavaScript --> 
      <td><input type="text" id="total_no_of_units" name="total_no_of_units" placeholder="total_no_of_units" required></td> 

      </tr> 

      <tr> 
      <td align="right"> <strong>Cost per Unit:</strong></td> 
      <!-- Added an Id to the form element so I can select it with JavaScript --> 
      <td><input type="text" id="cost_per_unit" name="cost_per_unit" placeholder="cost_per_unit" required></td> 

      </tr> 

      <tr> 

      <td align="right"> <strong>Total Acquisition Cost:</strong></td> 
      <!-- Added an Id to the form element so I can select it with JavaScript --> 
      <td><input type="text" id="total_cost_of_acquisition" name="total_cost_of_acquistion" placeholder="total_cost_of_acquistion" required></td> 


      </tr> 

      <tr> 
        <td align="right"> <strong>Asset Life:</strong></td> 
      <td><input type="text" name="life_of_assets_per_codal" placeholder="life_of_assets_per_codal" required></td> 
      </tr> 

      <tr> 
        <td align="right"> <strong>Years asset used:</strong></td> 
      <td><input type="text" name="no_year_assets_use" placeholder="no_of_year_assets_use" required></td> 
      </tr> 

      <tr> 
        <td align="right"> <strong>Depriciation Rate:</strong></td> 
      <td><input type="text" name="rate_depreciation" placeholder="rate_depreciation" required></td> 
      </tr> 

      <tr> 
        <td align="right"> <strong>Accumulated Depriciation:</strong></td> 
      <td><input type="text" name="accumulate_depreciation" placeholder="accumulate_depreciation_till_31/03/2016" required></td> 
      </tr> 

      <tr> 
        <td align="right"> <strong>Valuation:</strong></td> 
      <td><input type="text" name="value_as_on" placeholder="value_as_on_31/03/2016" required></td> 
      </tr> 

      <tr> 
        <td align="right"> <strong>Remarks:</strong></td> 
      <td><input type="text" name="remarks" placeholder="remarks" ></td> 
    </tr> 




     <!-- <tr> 
      <td align="right"> <strong>Status: </strong></td> 
      <td><select name="status" required> 
       <option></option> 
       <option>New</option> 
       <option>Old</option> 
       <option>Lost</option> 
       <option>Damage</option> 
       <option>Subject for Replacement</option> 
       <option>Archive</option> 
      </select> 
      </td> 
     </tr>--> 
      <tr> 
      <td colspan="2" align="center"><input type='submit' value=' Save ' name='submit'> 

      </tr> 
     </table> 
     <h4 align="right"><a href="mainpage1.php">BACK</a></h4> 
    </div> 
    </form> 

</body> 
</html> 
+0

不工作...... !!! –

+0

它给你任何错误吗?按Ctrl + Shift + J打开控制台时会发生什么? –