简体   繁体   中英

Setting Multiple Variables with php and MySQL

So I have a code I want to use

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);
        ?>

Now I only wanted the two images to show if the online field was 1, but they show no matter what. Does anyone know how I can fix this? Thanks.

For the sake of the argument:

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);
?>
            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" ?>';
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM