首先我有一个名为trade_field
+-----------+----------------+------------------+--------------+
| UID | durabletime | productionQTY | timestamp |
+-----------+----------------+------------------+--------------+
| 88 | 1234 | 6.00 |1444400000 |
----------------------------------------------------------------
然后我查询mysql并像这样分配:
$queryCopper = mysql_query("SELECT * FROM trade_field WHERE uid = ".$uid." AND fid = ".$fid."");
while($row = mysql_fetch_row($queryCopper)) {
$idCopper[] = $row['id'];
$timenow = time();
$durabletime = $row['durabletime'];
$Copperpdt = $row['production'];
$CopperQTY = number_format(($timenow - $row['timestamp']) / 60 * $Copperpdt);
if ($CopperQTY > $durabletime || ($CopperQTY > 1000 && $durabletime < 1000)) {
$CopperQTY = $durabletime;
} elseif($CopperQTY > 1000 && $durabletime > 1000) {
$CopperQTY = 1000;
} elseif($CopperQTY < 1000 && $CopperQTY < $durabletime) {
$CopperQTY = number_format(($timenow - $row['timestamp']) / 60 * $Copperpdt);
} else {
echo "Error";
};
$user_list_Copper[] = $row;
}
现在我们设置timenow = 1444450000
,$CopperQTY = 5000
(因为number_format(($1444450000 - 1444400000) / 60 * 6.00);
)
Geranal条件是:
if $CopperQTY > $durabletime
then $durabletime = $CopperQTY
之后,
if ($CopperQTY < 1000 && $CopperQTY > $durabletime)
then $durabletime = $CopperQTY
之后,
if $durabletime > $CopperQTY
then $CopperQTY = $CopperQTY
之后,
if ($durabletime > $CopperQTY && $CopperQTY > 1000)
then $CopperQTY = 1000
但是当我运行上面的代码时,系统会显示$CopperQTY = 5000
。
答案 0 :(得分:1)
根据您声明的条件,您的if-else-if-else
声明应如下:
if ($CopperQTY > $durabletime) {
$durabletime = $CopperQTY
} else if ($CopperQTY < 1000 && $CopperQTY > $durabletime) {
$durabletime = $CopperQTY
} else if ($durabletime > $CopperQTY) {
$CopperQTY = $CopperQTY
} else if ($durabletime > $CopperQTY && $CopperQTY > 1000) {
$CopperQTY = 1000
} else {
echo "Error";
}
由于$CopperQTY = 5000
和$durabletime = 1234
然后$durabletime
将等于5000
,if
语句将会中断。