Home  >  Article  >  Backend Development  >  PHP group purchase discount calculation formula_PHP tutorial

PHP group purchase discount calculation formula_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:23:162409browse

Copy code The code is as follows:

$price=$row['price']; //Original price
$nowprice=$ row['nowprice']; //Current price
$jiesheng=$price-$nowprice; //Saving amount
//$discount discount calculation
if ( $nowprice > 0 )
{
$discount = round(10 / ($price / $nowprice), 1);
}
else
{
$discount = 0;
}
if ( $discount <= 0 ) $discount = 0;


Full code:
Copy code The code is as follows:





徐州汽车网最新团购



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);
?>

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);
?>


  • buy














  • 原价 折扣 节省




}
?>

function getpic($pic){

}
mysql_close($con);
?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324539.htmlTechArticleCopy the code code as follows: $price=$row['price']; //Original price $nowprice=$row ['nowprice']; //Current price $jiesheng=$price-$nowprice; //Saving amount//$discount discount calculation if ( $nowprice 0 )...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn