php 团购折扣计算公式


Posted in PHP onNovember 24, 2011
$price=$row['price']; //原价 
$nowprice=$row['nowprice']; //现价 
$jiesheng=$price-$nowprice; //节省金额 
//$discount折扣计算 
if ( $nowprice > 0 ) 
{ 
$discount = round(10 / ($price / $nowprice), 1); 
} 
else 
{ 
$discount = 0; 
} 
if ( $discount <= 0 ) $discount = 0;

完整代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<title>徐州汽车网最新团购</title> 
<style type="text/css"> 
body{margin: 0 auto; text-align:center; padding:0} 
ul,li{margin:0; padding:0;list-style:none} 
body,td,th { 
font-size: 12px; 
} 
a:link { 
color: #333333; 
text-decoration: none; 
} 
a:visited { 
text-decoration: none; 
color: #333333; 
} 
a:hover { 
text-decoration: none; 
color: #FF3300; 
} 
a:active { 
text-decoration: none; 
} 
img{border:0;} 
/*Group buy*/ 
.groupbuy{ width:970px; border:1px solid #FEDDBA; padding:4px;} 
.groupbuy ul{width:146px; border:1px solid #FEDDBA; padding:2px; height:180px; float:left; margin:0 4px;} 
.groupbuy ul li{ text-align:center;} 
.groupbuy ul li.realprice{ background:#333; background:url(../images/groupprice.jpg) no-repeat right top; height:40px; line-height:40px; font-family:"Microsoft YaHei",Arial;display:block; font-weight:bold;color:#fff;} .groupbuy ul li.realprice img{ cursor:pointer;} 
.groupbuy ul li.realprice span{float:left; margin:0; padding:0} 
.groupbuy ul li.realprice span b{ font-size:18px;} 
.groupbuy ul li.supprice{ text-align:center;} 
.groupbuy ul li.supprice div table td{ background:#FDF4E3; text-align:center; } 
</style> 
</head> 
<body> 
<?php 
error_reporting(0); 
header("Content-type: text/html; charset=gbk"); 
$con = mysql_connect("localhost","mysql用户名","mysql密码"); 
if (!$con) 
{ 
die('Could not connect: ' . mysql_error()); 
} 
// some code 
mysql_select_db("tuanpcqc"); 
mysql_query("set names gbk"); 
$sql="select * from cenwor_tttuangou_product order by id desc limit 0,3"; 
$result = mysql_query($sql); 
?> 
<div class="groupbuy clear"> 
<?php 
while($row = mysql_fetch_array($result, MYSQL_BOTH)) { 
$id=$row['id']; 
$name = $row['name']; 
$price = $row['price']; 
$price=$row['price']; 
$nowprice=$row['nowprice']; 
$jiesheng=$price-$nowprice; 
if ( $nowprice > 0 ) 
{ 
$discount = round(10 / ($price / $nowprice), 1); 
} 
else 
{ 
$discount = 0; 
} 
if ( $discount <= 0 ) $discount = 0; 
$pic=$row['img']; 
$pic_arr=split(",",$pic); 
$picadd=$pic_arr[0]; 
//echo $picadd; 
$sql2="select * from cenwor_tttuangou_uploads where id=".intval($picadd); 
$result2 = mysql_query($sql2); 
$picurl = mysql_result($result2, 0,"url"); 
$picurl=str_replace("/demo/","/thumb/200x121/demo/",$picurl); 
?> 
<ul> 
<li><a href="http://tuan.pcqc.com.cn/?view=<?=$id?>" target="_blank"><img alt="" src="<?=$picurl?>" width="120" height="90" /></a></li> 
<li class="realprice"><span>¥<b><?=$nowprice?></b></span><a href="http://tuan.pcqc.com.cn/?view=<?=$id?>" target="_blank"><img alt="buy" src="images/buy.gif"/></a></li> 
<li class="supprice"> 
<div> 
<table> 
<tr> 
<td>原价</td> 
<td>折扣</td> 
<td>节省</td> 
</tr> 
<tr> 
<td><?=$price?></td> 
<td><?=$discount?>折</td> 
<td>¥<?=$jiesheng?></td> 
</tr> 
</table> 
</div> 
</li> 
</ul> 
<?php 
} 
?> 
</div> 
<?php 
function getpic($pic){ 
} 
mysql_close($con); 
?> 
</body> 
</html>
PHP 相关文章推荐
用php实现的下载css文件中的图片的代码
Feb 08 PHP
PHP的范围解析操作符(::)的含义分析说明
Jul 03 PHP
ThinkPHP的RBAC(基于角色权限控制)深入解析
Jun 17 PHP
怎样使用php与jquery设置和读取cookies
Aug 08 PHP
phpmyadmin config.inc.php配置示例
Aug 27 PHP
php 强制下载文件实现代码
Oct 28 PHP
PHP用反撇号执行外部命令
Apr 14 PHP
PHP基于phpqrcode生成带LOGO图像的二维码实例
Jul 10 PHP
php 计算两个时间相差的天数、小时数、分钟数、秒数详解及实例代码
Nov 09 PHP
通过源码解析Laravel的依赖注入
Jan 22 PHP
php中isset与empty函数的困惑与用法分析
Jul 05 PHP
php计数排序算法的实现代码(附四个实例代码)
Mar 31 PHP
php中$_REQUEST、$_POST、$_GET的区别和联系小结
Nov 23 #PHP
打造超酷的PHP数据饼图效果实现代码
Nov 23 #PHP
DISCUZ在win2003环境下 Unable to access ./include/common.inc.php in... 的问题终极解决方案
Nov 21 #PHP
一个PHP的QRcode类与大家分享
Nov 13 #PHP
PHP提取字符串中的图片地址[正则表达式]
Nov 12 #PHP
PHP学习散记_编码(json_encode 中文不显示)
Nov 10 #PHP
PHP字符串函数系列之nl2br(),在字符串中的每个新行 (\n) 之前插入 HTML 换行符br
Nov 10 #PHP
You might like
PHP脚本的10个技巧(3)
2006/10/09 PHP
PHP中的正规表达式(一)
2006/10/09 PHP
phpExcel中文帮助手册之常用功能指南
2014/08/18 PHP
php使用curl并发减少后端访问时间的方法分析
2016/05/12 PHP
PHP 实现手机端APP支付宝支付功能
2018/06/07 PHP
在页面上点击任一链接时触发一个事件的代码
2007/04/07 Javascript
锋利的jQuery 要点归纳(一) jQuery选择器
2010/03/21 Javascript
Javascript 中的 call 和 apply使用介绍
2012/02/22 Javascript
JS设置获取cookies的方法
2014/01/26 Javascript
Vue.js基础知识小结
2017/01/13 Javascript
微信小程序 action-sheet 反馈上拉菜单简单实例
2017/05/11 Javascript
node.js通过axios实现网络请求的方法
2018/03/05 Javascript
vue自动化表单实例分析
2018/05/06 Javascript
Vue项目安装插件并保存
2019/01/28 Javascript
一篇文章弄懂javascript中的执行栈与执行上下文
2019/08/09 Javascript
详解Vue中Axios封装API接口的思路及方法
2020/10/10 Javascript
Python贪心算法实例小结
2018/04/22 Python
Django rest framework实现分页的示例
2018/05/24 Python
python实现输入数字的连续加减方法
2018/06/22 Python
python中PS 图像调整算法原理之亮度调整
2019/06/28 Python
Python读写锁实现实现代码解析
2020/11/28 Python
jurlique茱莉蔻英国官网:澳洲天然护肤品
2018/08/03 全球购物
美国珠宝店:Helzberg Diamonds
2018/10/24 全球购物
职高毕业生自我鉴定
2013/10/21 职场文书
大专毕业生自我鉴定
2013/11/21 职场文书
中专三年学习的个人自我评价
2013/12/12 职场文书
个人现实表现材料
2014/02/04 职场文书
打架检讨书2000字
2014/02/22 职场文书
财务简历的自我评价
2014/03/05 职场文书
本科毕业生自荐信
2014/06/02 职场文书
学习焦裕禄同志为人民服务思想汇报
2014/09/10 职场文书
远程教育学习心得体会
2016/01/23 职场文书
Python提取PDF指定内容并生成新文件
2021/06/09 Python
浅谈Python数学建模之固定费用问题
2021/06/23 Python
实体类或对象序列化时,忽略为空属性的操作
2021/06/30 Java/Android
Java使用Unsafe类的示例详解
2021/09/25 Java/Android