-1

所以我有一个我想使用的代码

mysql_select_db("website", $con);
    $result=mysql_query("SELECT * FROM characters where online='1'");
    while ($row=
                mysql_fetch_array($result))
                {
                echo $row['name'];
                }
                if ($row['race'] == "1");
                {
                echo '<img src="img/8-0.gif" />';
                }
                if ($row['class'] == "3");
                {
                echo '<img src="img/3.gif" ?>';
                }
            mysql_close($con);
        ?>

现在我只希望这两个图像显示在线字段是否为 1,但无论如何它们都会显示。有谁知道我该如何解决这个问题?谢谢。

4

2 回答 2

3

为了论证:

mysql_select_db("website", $con);
$result=mysql_query("SELECT * FROM characters where online='1'");
while ($row= mysql_fetch_array($result))
{
    echo $row['name'];
//} This bracket would immediately close your query processing and only display the last images. Or is that the desired behaviour?
    if($row['isOnline'] == '1') { //Makes sure, that 'isOnline' is set before displaying.
            if ($row['race'] == "1");
            {
            echo '<img src="img/8-0.gif" />';
            }
            if ($row['class'] == "3");
            {
            echo '<img src="img/3.gif" ?>';
            }
    }
} //This bracket closes the actual query result handling
mysql_close($con);
?>
于 2012-07-24T11:19:10.187 回答
0
            if ($row['race'] == "1" AND $row['online'] == 1);
            {
            echo '<img src="img/8-0.gif" />';
            }
            if ($row['class'] == "3" AND $row['online'] == 1);
            {
            echo '<img src="img/3.gif" ?>';
            }
于 2012-07-24T11:17:20.137 回答