Copy codeThe 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:Copy codeThe Code is as follows: <! 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> Xuzhou Automotive Network's latest group buying </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 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 );
?>
<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 "> "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 "> </a> </li>
<Li class = "supprice">
<Div>
<Table>
<Tr>
<Td> original price </td>
<Td> discount </td>
<Td> Save </td>
</Tr>
<Tr>
<Td> <? = $ Price?> </Td>
<Td> <? = $ Discount?> Discount </td>
<Td> ¥ <? = $ Jiesheng?> </Td>
</Tr>
</Table>
</Div>
</Li>
</Ul>
<? Php
}
?>
</Div>
<? Php
Function getpic ($ pic ){
}
Mysql_close ($ con );
?>
</Body>
</Html>