0

我在while循环中有这段代码。

$hometeamwin=(lose,win) 所以上面的那段代码正在打印“winlose”

如果在 $hometeamwin 中出现“失败”,我希望它打印“失败”(但只有一次!)

如果没有出现“输”打印“赢”(但只有一次!)

4

1 回答 1

2

如果我了解您的问题(我不肯定),您想查看所有投注,如果其中任何一个导致输了,那么在您列出所有投注后,您想根据是否显示输赢结果中有损失。我复制了您的代码并添加了 3 行标有 #ADDED。添加这三行来实现我所描述的。

if($num_rows) {
    $wonBet = true;  #ADDED
    while ($row = mysql_fetch_assoc($result)) {
        echo "<tr>";
        if(!$row["ht_score"]) {
            $halftime = "-";
        } else {
            $halftime = $row["ht_score"];
        }
        if(!$row["ft_score"]) {
            $fulltime = "-";
        } else {
            $fulltime = $row["ft_score"];
        }

        echo "<td>" . $row["home_team"] . "</td>" . "<td>" . " vs " . "</td>" . "<td>" . $row["away_team"] . "</td>" . "<td>" . $halftime . "</td>" . "<td>" . $fulltime . "</td>";

        $value = $fulltime;
        $apart = explode('-',$value); 
        if($apart[0] > $apart[1] && $row["home_id"]==$row["winningid"]) {
            $hometeamwin = "Win";
        } else if($apart[0] < $apart[1] && $row["away_id"]==$row["winningid"]) {
            $hometeamwin = "Win"; 
        } else if($apart[0] == $apart[1] && !$row["winningid"]) {
            $hometeamwin = "Win"; 
        } else { 
            $hometeamwin = "lose";    
        }

        if($fulltime!=$row["ft_score"]) {
             $hometeamwin = "";
        }
        if($hometeamwin == "lose"){  #ADDED
            $wonBet = false;         #ADDED
        }                            #ADDED
        echo "<td>" . $hometeamwin . "</td>";
        echo "</tr>";
    }

    echo ($wonBet) ? "You won bet" : "You lost bet";  #ADDED
}
于 2012-12-17T22:47:52.110 回答