首先,我有一个名为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);
)一般情况是:
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
。 最佳答案
根据您所说的条件,您的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
语句将中断。