【问题标题】:php/css error, don`t load Style to some objectsphp/css 错误,不要将样式加载到某些对象
【发布时间】:2016-02-23 21:37:42
【问题描述】:

我的 php 代码出现了一些奇怪的问题 当我尝试输出这个echo "<div class='button menu' onclick=\"javascript:location.href='$baseURI'\">Menu</div>";

有时它不加载 css,甚至不加载 div -标签,只是简单的“菜单”字符串 它总是打印在我的 table -tags

之前

这怎么可能?

PHP-代码:

<?php
$root_dir = $_SERVER['PHP_SELF'];
echo "<link rel='stylesheet' href='style.css' type='text/css'>";
if (!isset($_GET['command'])) {
    echo "<div class='button' onclick=\"javascript:location.href='$baseURI?command=show'\">Personaldaten anzeigen</div>";
    //echo "<div class='button' onclick=\"javascript:location.href='$baseURI?command=new'\">neue Person anlegen</div>";
    //echo "<div class='button' onclick=\"javascript:location.href='$baseURI?command=work'\">Personaldaten bearbeiten</div>";
} else {
    if ($_GET['command'] == "show") {
        openSQL();
        $sqlbefehl = 'select * from kontakt';
        @mysql_query("SET NAMES 'utf8'");
        $ergebnis = @mysql_query($sqlbefehl); // SQL-Befehl an die Datenbank schicken
        $spalten  = @mysql_num_fields($ergebnis);
        echo "<table class='style'>";
        echo "<tr>";
        for ($i = 0; $i < $spalten; $i++) {
            echo "<th class='th'>" . mysql_field_name($ergebnis, $i) . "</th>";
        }
        echo "</tr>";
        while (false != ($row = mysql_fetch_row($ergebnis))) {
            echo "<tr>";
            for ($i = 0; $i < sizeof($row); $i++) {
                echo "<td>$row[$i]</td>";
            }
            echo "</tr>";
        }
        echo "</table";
    }
    echo "<div class='button menu' onclick=\"javascript:location.href='$baseURI'\">Menu</div>";
}
function openSQL()
{
    $server   = "127.0.0.1";
    $user     = "root";
    $passwort = "";
    $db       = "schule";
    $dblink   = @mysql_connect($server, $user, $passwort);
    if (!@mysql_select_db($db)) {
        echo "<br>Keine Verbindung zur Datenbank $db möglich!";
        echo "<br>" . mysql_error();
        die();
    }
}
?>

CSS代码:

body{
    font-family: Verdana;
    color: #fff;
    background-color: #000;

}
.style{
    border-collapse: collapse;
    text-align: center;
}

.style table,.style th,.style td {
    border: 1px solid white;
}
.style td {
    overflow: hidden;
    font-size: 12px;
}
.button{
    height: 68px;
    width: 200px;
    border: 3px orange solid;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    border-radius: 5px;
    vertical-align: center;
    font-size: 24px;
    margin-top: 15px;
    background-color: #000;
}
.menu{
    height: 36px;
    width: 75px;
}
.delBtn{
    height: 36px;
    width: 95px;
}
.del{
    background-image: url(del.png);
    background-repeat: no-repeat;
    width:24px;
    height: 24px;
    background-size: 25px 25px;
}
.edit{
    background-image: url(edit.png);
    background-repeat: no-repeat;
    background-position: center;
    width:24px;
    height: 24px;
    background-size: 40px 40px;
}

【问题讨论】:

  • 您将不应该的标签混合在一起。 元素应该进入 部分,而大多数标签(
    等)应该进入 。考虑使用 html 验证器来通知您潜在的其他问题。
  • 你能在$baseURI变量中包含一个var_dump吗?我没有看到它被设置在任何地方:p
  • 你能提供实时链接吗??
  • 我会尽快发布输出 DOM 你的权利,$baseURI 未定义将在家里测试它,不能让 xampp 在这里工作
  • 我发现您的 table 标签未正确关闭。关闭&lt;/table&gt; 的回声缺少'>'。

标签: php html css sql


【解决方案1】:

所以我回答我自己的问题。这是结束表标记处缺少的“>”。由于我修复了丢失的字符,代码现在可以正常工作了。

感谢您的所有努力

【讨论】:

    猜你喜欢
    相关资源
    最近更新 更多
    热门标签