PHP、Mysql、引导表不工作

PHP、Mysql、引导表不工作,php,mysql,Php,Mysql,我在一个剧本前坐了几个小时,但我发现它不能正常工作。我想用mysql数据填充一个引导表。不幸的是,我总是得到其他信息或错误消息。 如果有人能看一下剧本那就太好了 $conn = new mysqli($servername, $username, $password, $dbname); $conn->set_charset("utf8"); $sql = "SELECT Osman, Tanja, Christiane, Marcella, Magarita, Nathalie, Kom

我在一个剧本前坐了几个小时,但我发现它不能正常工作。我想用mysql数据填充一个引导表。不幸的是,我总是得到其他信息或错误消息。 如果有人能看一下剧本那就太好了

$conn = new mysqli($servername, $username, $password, $dbname);
$conn->set_charset("utf8");
$sql = "SELECT Osman, Tanja, Christiane, Marcella, Magarita, Nathalie, Kommentar, Gutschein, EC FROM Salon1_10_04_2016";
$results = $conn->query($sql);

 <table class="table table-hover">
  <thead>
  <tr>
    <th>Firstname</th>
    <th>Lastname</th>
    <th>Email</th>
  </tr>
</thead>
<tbody>
       <?while($row = mysqli_fetch_assoc($result)) {
            echo"<tr class='table_row'>";
            echo"<td>" . $row['Osman'] . "</td>";
            echo"<td>" . $row['Tanja'] . "</td>";
            echo"<td>" . $row['Christiane'] . "</td>";
            echo"<td>" . $row['Marcella'] . "</td>";
            echo"<td>" . $row['Magarita'] . "</td>";
            echo"<td>" . $row['Nathalie'] . "</td>";
            echo"<td>" . $row['Kommentar'] . "</td>";
            echo"<td>" . $row['Gutschein'] . "</td>";
            echo"<td>" . $row['EC'] . "</td>";
            echo"</tr>";
             } echo"</table>";}?>

如果您将面向对象的样式与过程混合,请尝试以下方法:

<?php
$conn = new mysqli($servername, $username, $password, $dbname);
$conn->set_charset("utf8");
$sql = "SELECT Osman, Tanja, Christiane, Marcella, Magarita, Nathalie, Kommentar, Gutschein, EC FROM Salon1_10_04_2016";
$results = $conn->query($sql);
?>
<table class = "table table-hover">
    <thead>
        <tr>
            <th>Firstname</th>
            <th>Lastname</th>
            <th>Email</th>
        </tr>
    </thead>
    <tbody>
        <?php
        while ($row = $results->fetch_assoc()) {
            echo"<tr class='table_row'>";
            echo"<td>" . $row['Osman'] . "</td>";
            echo"<td>" . $row['Tanja'] . "</td>";
            echo"<td>" . $row['Christiane'] . "</td>";
            echo"<td>" . $row['Marcella'] . "</td>";
            echo"<td>" . $row['Magarita'] . "</td>";
            echo"<td>" . $row['Nathalie'] . "</td>";
            echo"<td>" . $row['Kommentar'] . "</td>";
            echo"<td>" . $row['Gutschein'] . "</td>";
            echo"<td>" . $row['EC'] . "</td>";
            echo"</tr>";
        }
        ?>
    </tbody>
</table>
不管怎样,表体中的列数与AD中定义的列数不同,请确保SQL是有效的

更新:如果要检查字符串中是否有值,可以为该值定义一个简单函数,如果值为空,该函数将返回所需的字符:

<?php
function checkNull($str){
    if(!trim($str)) return '-';
    else return $str;
}

// how to use it:
echo"<td>" . checkNull($row['Osman']) . "</td>";
?>

当我实际从$results中进行var_转储时,我得到:objectmysqli_result3 5{[current_field]=>int0[field_count]=>int9[length]=>NULL[num_rows]=>int1[type]=>int0}为什么在这两者之间打开第二个php标记,有html和css脚本。在while循环中,您试图从$result而不是从$results中获取。谢谢!你知道吗,当mysql字段显示空值时,我如何显示-?这是最后的想法,比脚本完成。