优惠网 > 优惠大全 > 求解怎么做?PHP代码计算商品打折后的价格。求代码

求解怎么做?PHP代码计算商品打折后的价格。求代码

作者:优优 | 分类:优惠大全 | 浏览量:66
发表时间:2025-02-26 14:39:23

完全依照图片效果,代码如下:


1、html 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<html>
<head>
<title>计算商品折扣价格</title>
</head>
<body>
<form id= form1 name= form1 method= post action= calc.php >
<table width= 314 border= 1 >
<tr>
<td width= 92 >商品名称:</td>
<td width= 206 ><label for= textfield ></label>
<input type= text name= spmc id= spmc /></td>
</tr>
<tr>
<td>商品单价:</td>
<td><input type= text name= spdj id= spdj /> 元 </td>
</tr>
<tr>
<td>促销折扣:</td>
<td><input type= text name= cxzk id= cxzk /> % </td>
</tr>
<tr align= center >
<td colspan= 2 ><input type= submit name= button id= button value= 计算折扣价格 /></td>
</tr>
</table>
</form>
</body>
</html>


2、calc.php 文件

1
2
3
4
5
6
7
8
9
10
<?php
$spmc = $_POST[ spmc ];
$spdj = $_POST[ spdj ];
$cxzk = $_POST[ cxzk ];
$zkjg = $spdj * $cxzk/100;
echo 商品名称: . $spmc . ;
echo 商品单价: . $spdj .;
echo 促销折扣: . $cxzk . % ;
echo 折后价格: . $zkjg .;
?>


效果图:




示例文件下载:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
error_reporting(E_ALL & ~E_NOTICE);
if($_POST[ t ]== yy )
{
$f= % ;//计算符号
$p=$_POST[ p ];//商品名称
$j=$_POST[ j ];//商品价格
$y=$_POST[ y ].$f;//百分比
$js=$j*$y/100;//计算
?>
<p>商品名称:<?php echo $p;?></p>
<p>商品单价:<?php echo $j;?></p>
<p>促销折扣:<?php echo $y;?></p>
<p>折后价格:<?php echo $js;?></p>
<?php }?>
<form id= form1 name= form1 method= post action= >
<input type= hidden name= t value= yy />
<table width= 400 border= 0 >
<tr>
<td width= 104 >商品名称</td>
<td width= 286 >
<input type= text name= p id= p />
</td>
</tr>
<tr>
<td>商品单价</td>
<td><input type= text name= j id= j /></td>
</tr>
<tr>
<td>促销折扣</td>
<td><input type= text name= y id= y /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type= submit name= button id= button value= 提交 /></td>
</tr>
</table>
</form>


直接复制以上代码,新建立一个*.php 文件 粘贴进去,访问即可.

你的要求不是太清楚?你可以详细的描述一下,你是想输入原价以及折扣得到现在价还是怎么样?

粤ICP备2024332802号-3 | 优惠信息大全 | Sitemap
深圳市华诚易配电子商务有限公司 旗下网站
本站内容由AI生成或转载自网络,如有版侵,请与我们联系