php 團(tuán)購(gòu)折扣計(jì)算公式
更新時(shí)間:2011年11月24日 16:26:28 作者:
php 團(tuán)購(gòu)折扣計(jì)算公式,因?yàn)樽罱枰{(diào)用天天團(tuán)購(gòu)程序的數(shù)據(jù),代碼比較不好找,所以直接自己寫個(gè)代碼讀取mysql的數(shù)據(jù)。
復(fù)制代碼 代碼如下:
$price=$row['price']; //原價(jià)
$nowprice=$row['nowprice']; //現(xiàn)價(jià)
$jiesheng=$price-$nowprice; //節(jié)省金額
//$discount折扣計(jì)算
if ( $nowprice > 0 )
{
$discount = round(10 / ($price / $nowprice), 1);
}
else
{
$discount = 0;
}
if ( $discount <= 0 ) $discount = 0;
完整代碼:
復(fù)制代碼 代碼如下:
<!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>徐州汽車網(wǎng)最新團(tuán)購(gòu)</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 target="_blank"><img alt="" src="<?=$picurl?>" width="120" height="90" /></a></li>
<li class="realprice"><span>¥<b><?=$nowprice?></b></span><a target="_blank"><img alt="buy" src="images/buy.gif"/></a></li>
<li class="supprice">
<div>
<table>
<tr>
<td>原價(jià)</td>
<td>折扣</td>
<td>節(jié)省</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>
相關(guān)文章
PHP實(shí)現(xiàn)接收二進(jìn)制流轉(zhuǎn)換成圖片的方法
這篇文章主要介紹了PHP實(shí)現(xiàn)接收二進(jìn)制流轉(zhuǎn)換成圖片的方法,結(jié)合實(shí)例形式分析了php文件、目錄及圖形操作的相關(guān)技巧,需要的朋友可以參考下2017-01-01
PHP中類屬性與類靜態(tài)變量的訪問(wèn)方法示例
這篇文章主要介紹了PHP中類屬性與類靜態(tài)變量的訪問(wèn)方法,結(jié)合實(shí)例形式對(duì)比分析了php中類的屬性、靜態(tài)變量及常量的各種訪問(wèn)技巧,需要的朋友可以參考下2016-07-07
使用PHP實(shí)現(xiàn)生成HTML靜態(tài)頁(yè)面
在PHP網(wǎng)站開(kāi)發(fā)中為了網(wǎng)站推廣和SEO等需要,需要對(duì)網(wǎng)站進(jìn)行全站或局部靜態(tài)化處理,PHP生成靜態(tài)HTML頁(yè)面有多種方法,比如利用PHP模板、緩存等實(shí)現(xiàn)頁(yè)面靜態(tài)化,今天就以PHP實(shí)例教程形式討論P(yáng)HP生成靜態(tài)頁(yè)面的方法。2015-11-11
php異常:Parse error: syntax error, unexpected T_ENCAPSED_AND_W
PHP會(huì)出現(xiàn)eval()'d code error 錯(cuò)誤提示的原因一般都是因?yàn)槟0邋e(cuò)誤,原因有以下幾種情況2011-05-05
PHP實(shí)現(xiàn)生成唯一會(huì)員卡號(hào)
當(dāng)每個(gè)會(huì)員登錄進(jìn)來(lái),在查詢數(shù)據(jù)庫(kù)的情況下生成一組數(shù)字或者是數(shù)字與字母組合不重復(fù)的會(huì)員卡號(hào),接下來(lái),給大家演示一個(gè)小程序,基于php實(shí)現(xiàn)生成唯一會(huì)員卡號(hào),有需要的朋友一起來(lái)學(xué)習(xí)吧2015-08-08
php獲取服務(wù)器信息的實(shí)現(xiàn)代碼
php獲取服務(wù)器信息的一段代碼,包括獲取mysql數(shù)據(jù)庫(kù)版本信息、GD庫(kù)信息、php上傳相關(guān)信息等。有需要的朋友,可以參考下2013-02-02
PHP+redis實(shí)現(xiàn)添加處理投票的方法
這篇文章主要介紹了PHP+redis實(shí)現(xiàn)添加處理投票的方法,結(jié)合實(shí)例較為詳細(xì)的分析了PHP+redis數(shù)據(jù)庫(kù)操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11

