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中的MYSQL常用函数(php下操作数据库必备)
Sep 12 PHP
第4章 数据处理-php正则表达式-郑阿奇(续)
Jul 04 PHP
关于PHP的相似度计算函数:levenshtein的使用介绍
Apr 15 PHP
PHP在线生成二维码(google api)的实现代码详解
Jun 04 PHP
解析使用ThinkPHP应该掌握的调试手段
Jun 20 PHP
简单分析ucenter 会员同步登录通信原理
Aug 25 PHP
yii中widget的用法
Dec 03 PHP
php实现删除空目录的方法
Mar 16 PHP
php搜索文件程序分享
Oct 30 PHP
thinkPHP交易详情查询功能详解
Dec 02 PHP
Laravel学习教程之model validation的使用示例
Oct 23 PHP
PHP回调函数概念与用法实例分析
Nov 03 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
解析CodeIgniter自定义配置文件
2013/06/18 PHP
php加速器eAccelerator的配置参数、API详解
2014/05/05 PHP
php中动态调用函数的方法
2015/03/16 PHP
ThinkPHP5框架缓存查询操作分析
2018/05/30 PHP
个人总结的一些关于String、Function、Array的属性和用法
2007/01/10 Javascript
JavaScript 空位补零实现代码
2010/02/26 Javascript
基于javascript实现的快速排序
2016/12/02 Javascript
在DWR中实现直接获取一个JAVA类的返回值的两种方法
2016/12/25 Javascript
[10:42]Team Liquid Vs Newbee
2018/06/07 DOTA
解析Python中的异常处理
2015/04/28 Python
Python中基础的socket编程实战攻略
2016/06/01 Python
Python编程之黑板上排列组合,你舍得解开吗
2017/10/30 Python
Python 中导入csv数据的三种方法
2018/11/01 Python
python 使用 requests 模块发送http请求 的方法
2018/12/09 Python
python3使用matplotlib绘制散点图
2019/03/19 Python
Python 3.8中实现functools.cached_property功能
2019/05/29 Python
详解pytorch 0.4.0迁移指南
2019/06/16 Python
Python使用enumerate获取迭代元素下标
2020/02/03 Python
Python爬虫教程知识点总结
2020/10/19 Python
最新PyCharm 2020.2.3永久激活码(亲测有效)
2020/11/26 Python
让IE支持CSS3的不完全兼容方案
2014/09/19 HTML / CSS
CSS3实现翘边的阴影效果的代码示例
2016/06/13 HTML / CSS
HTML5拍照和摄像机功能实战详解
2019/01/24 HTML / CSS
全球酒店预订网站:Hotels.com
2016/08/10 全球购物
世界上最好的威士忌和烈性酒购买网站:The Whisky Exchange
2016/11/20 全球购物
GOOD AMERICAN官网:为曲线性感而设计
2017/12/28 全球购物
丝芙兰香港官网:Sephora香港
2018/03/13 全球购物
linux面试题参考答案(7)
2014/07/24 面试题
结构工程个人自荐信范文
2013/11/30 职场文书
给女朋友的道歉信
2014/01/10 职场文书
自我鉴定 电子商务专业
2014/01/30 职场文书
中学生操行评语
2014/04/24 职场文书
毕业论文指导教师评语
2014/12/30 职场文书
离职感谢信
2015/01/21 职场文书
2015年个人工作总结报告
2015/04/25 职场文书
刑事上诉状(无罪)
2015/05/23 职场文书