duandun3178 2014-09-30 12:02
浏览 81

PHP动态计算

I have an HTML form that displays a list of pricing options called back from information from my database, I have created some functions to use this information as calculations to populate the rest of the form. Although I would like for the user to be able to change the values and the calculations to update with this but I can't seem to get that to work!

This is my HTML form code

<div class="form-group">
    <label class="col-sm-2 control-label" for="totalprice">Total Price</label>
    <input class="input" name="totalprice" type="text" id="totalprice" value="<?php echo $total_price; ?>">
</div>
<div class="form-group">
    <label class="col-sm-2 control-label" for="rrp">RRP</label>
    <input class="input" name="rrp" type="text" id="rrp"  value="<?php echo $rrp_price; ?>">
</div>
<div class="form-group">
    <label class="col-sm-2 control-label" for="delivery">Delivery</label>
    <input class="input" name="delivery" type="text"  id="delivery" value="<?php echo $delivery; ?>">
</div>
<div class="form-group">
    <label class="col-sm-2 control-label" for="rfl">RFL</label>
    <input class="input" name="rfl" type="text"  id="rfl" value="<?php echo $rfl; ?>">
</div>
<div class="form-group">
    <label class="col-sm-2 control-label" for="netprice">Nett Price</label>
    <input class="input" name="netprice" type="text"  id="netprice" value="<?php echo $net_price; ?>">
</div>
</div>

and this is my PHP code to get the values and do the calculations

$result = mysql_query("SELECT created_by, accessories, customer_ID, total_price, rrp FROM new_quote WHERE quote_ID = '$quote_ID'");
$data = mysql_fetch_row($result);
$sales_person = $data[0];
$accessories = $data[1];
$customer_ID = $data[2];
$total_price = str_replace('£', '', $data[3]);
$rrp_price = $data[4];

$rrp_price2 = preg_replace('/[^A-Za-z0-9\-]/', '', $rrp_price); 
$rrp_price = substr($rrp_price2, 3);

$total_price2 = preg_replace('/[^A-Za-z0-9\-]/', '', $total_price);
$total_price = substr($total_price2, 3);

$rfl = $total_price - $rrp_price - $delivery - $care_products;

$net_price = ($total_price - $rfl) / 1.2;

$gr_profit = ($net_price * 0.11) + 500;

$po_profit = ($net_price * 0.03);
  • 写回答

1条回答 默认 最新

  • duanshan3331 2014-09-30 12:12
    关注

    PHP is server-side scripting language, so if you want to do new calculation, you have to call the server again (because there is the place where I see that you do them). If you want to do the calculation without a request to the server, you have to use a client-side language like JavaScript

    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)