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