尝试翻译此输出代码有什么错误

时间:2018-10-09 20:50:10

标签: php

如何翻译此代码的输出:

<b>N. di pagine:</b> {$_SESSION["printDetails"]["pages"]}<br>
<b>Tipo:</b> {$_SESSION["printDetails"]['color']}<br>
<b>Formato:</b> {$_SESSION["printDetails"]['paper_size']}<br>
<b>Orientamento:</b> {$_SESSION["printDetails"]['orientation']}<br>
<b>Fronte/Retro:</b> {$_SESSION["printDetails"]['print_type']}<br>
<b>Copie:</b> {$_SESSION["printDetails"]['copies']}<br><br>

我尝试用这种方式编辑代码:

<b>Colore:</b> if($_SESSION["printDetails"]["color"]=="bw"){echo "Bianco/Nero"; } else{echo "Colori";}<br>

但什么都没有!

HTML代码已经包含在PHP代码中

if (mysql_query($query)) {
            $msg = "Done";
            // send message to admin regarding printing information //
            $queryStr = "SELECT * FROM users WHERE type = 'admin'";
            $res = mysql_query($queryStr);
            $adminDetails = mysql_fetch_array($res);
            $emailContent = "Caro admin, <br><br>
                            Hai una nuova richiesta di stampa da <b><i>{$userDetails["user_name"]}</i></b>. Ecco i dettagli: <br><br>
                            <b>N. di pagine:</b> {$_SESSION["printDetails"]["pages"]}<br>
                            <b>Tipo:</b> {$_SESSION["printDetails"]['color']}<br>
                            <b>Formato:</b> {$_SESSION["printDetails"]['paper_size']}<br>
                            <b>Orientamento:</b> {$_SESSION["printDetails"]['orientation']}<br>
                            <b>Fronte/Retro:</b> {$_SESSION["printDetails"]['print_type']}<br>
                            <b>Copie:</b> {$_SESSION["printDetails"]['copies']}<br><br>
                            Grazie, <br>
                            -WeScriba team";
            sendEmail($adminDetails['user_email_address'], "Nuova richiesta di stampa", $emailContent);
        } else {
            $msg = "notsaved";
        }

1 个答案:

答案 0 :(得分:0)

您需要使用PHP标签<?php?>来表示您正在HTML和PHP之间进行交换:

<b>Colore:</b>
    <?php
    if($_SESSION["printDetails"]["color"] == "bw") {
        echo "Bianco/Nero";
    } else {
    echo "Colori";
    }
    ?>
<br>

或使用echo在PHP代码本身中输出HTML:

<?php
    echo "<b>Colore:</b>";
    if($_SESSION["printDetails"]["color"] == "bw") {
        echo "Bianco/Nero";
    } else {
    echo "Colori";
    }
    echo "<br>";
?>