Php Group buying discount calculation formula

Source: Internet
Author: User
The formula for calculating the discount for group buying in php. because the daily group buying program data needs to be called recently, the code is hard to find, so you can directly write a code to read mysql data. The code is as follows:


$ Price = $ row ['price']; // original price
$ Nowprice = $ row ['nowprice']; // current price
$ Jiesheng = $ price-$ nowprice; // saved amount
// $ Discount calculation
If ($ nowprice> 0)
{
$ Discount = round (10/($ price/$ nowprice), 1 );
}
Else
{
$ Discount = 0;
}
If ($ discount <= 0) $ discount = 0;



Complete code:

The code is as follows:






Xuzhou automotive network latest group buying



Error_reporting (0 );
Header ("Content-type: text/html; charset = gbk ");
$ Con = mysql_connect ("localhost", "mysql username", "mysql password ");
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 );
?>


  • "Target =" _ blank ">" width = "120" height = "90"/>

  • "Target =" _ blank ">














  • Original price Discount Save
    Discount




}
?>


Function getpic ($ pic ){

}
Mysql_close ($ con );
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.