使用PHP替换数据库字符串

时间:2013-04-19 06:06:49

标签: php database string replace

这是我的代码:

            echo "<td>" . $row4['CMUSERID'] . "</td>";
            echo "<td>" . $row4['CMCLAS'] . "</td>";
            echo "<td>" . $row4['CMRACE'] . "</td>";
            echo "<td>" . $row4['CMGEND'] . "</td>";
            echo "<td>" . $row4['CMSTRE'] . "</td>";
            echo "<td>" . $row4['CMDEXT'] . "</td>";
            echo "<td>" . $row4['CMCONS'] . "</td>";
            echo "<td>" . $row4['CMWISD'] . "</td>";

以下是显示结果的页面链接:

http://oge.sytes.net/zetzer/includes/characters.php

如何修改我的PHP代码以从显示中消除PlayerClass和PlayerRace,所以如果他们没有选择一个类或种族,它会显示为空?我无法在数据库中更改它,因此必须在php显示中替换它

1 个答案:

答案 0 :(得分:1)

        echo "<td>" . $row4['CMUSERID'] . "</td>";
        echo "<td>";
             echo $row4['CMCLAS'] == "PlayerClass" ? "&nbsp;" : $row4['CMCLAS'];
        echo "</td>";
        echo "<td>";
             echo $row4['CMRACE'] == "PlayerRace" ? "&nbsp;" : $row4['CMRACE'];
        echo "</td>";
        echo "<td>" . $row4['CMGEND'] . "</td>";
        echo "<td>" . $row4['CMSTRE'] . "</td>";
        echo "<td>" . $row4['CMDEXT'] . "</td>";
        echo "<td>" . $row4['CMCONS'] . "</td>";
        echo "<td>" . $row4['CMWISD'] . "</td>";

您可能希望将“&nbsp;”替换为您喜欢的任何内容。