php - 无法在 php 中使用 css 设置表格样式

标签 php css

即使我有表格的插入样式,我也无法在 css 中设置表格样式。

<style>
table, th, td 
{
border: 1px solid black;
}
</style>

以上是代码的简单风格

<div class="container">
    <table class="u-full-width">
    <?php


      $result=mysqli_query($connection,"SELECT * FROM register");

  }
  else
  {
      $result=mysqli_query($connection,"SELECT * FROM Persons WHERE username LIKE '".$Search."%'");
  }
  echo "<table border='1'>
  <tr>
  <th>username</th>
  <th>password</th>
  <th>Name</th>
  <th>gender</th>
  <th>age</th>
  <th>Contact</th>
  <th>address</th>
  <th>email</th>
  <th>occupation</th>     
  </tr>";

    while($row=mysqli_fetch_array($result))
  {
      echo "<tr>";
      echo "<td>" . $row['Username'] . "</td>"; 
      echo "<td>" . $row['password'] . "</td>";
      echo "<td>" . $row['Name'] . "</td> ";
      echo "<td>" . $row['gender'] . "</td>";
      echo "<td>" . $row['age'] . "</td> ";
      echo "<td>" . $row['contact'] . "</td>";
      echo "<td>" . $row['address'] . "</td>";
      echo "<td>" . $row['email'] . "</td>";
      echo "<td>" . $row['occupation'] . "</td>";
      echo "</tr>";
  }
  echo"</table>";
  mysqli_close($connection);
  ?>
     </div>
     </table>

上面是用来显示表格的。我可以知道我可以做什么,以便它显示带有 css 的表格。谢谢。

最佳答案

这是因为您使用 php 动态插入表格。

试试这个

<div class="container">
<table class="u-full-width" border='1'>
<?php

if () {//note code is incomplete, might be copy pasting issue
  $result=mysqli_query($connection,"SELECT * FROM register");

}
else
{
  $result=mysqli_query($connection,"SELECT * FROM Persons WHERE username LIKE '".$Search."%'");
}
?>

<tr>
<th>username</th>
<th>password</th>
<th>Name</th>
<th>gender</th>
<th>age</th>
<th>Contact</th>
<th>address</th>
<th>email</th>
<th>occupation</th>     
</tr>

<?php
while($row=mysqli_fetch_array($result))
{
  echo "<tr>";
  echo "<td>" . $row['Username'] . "</td>"; 
  echo "<td>" . $row['password'] . "</td>";
  echo "<td>" . $row['Name'] . "</td> ";
  echo "<td>" . $row['gender'] . "</td>";
  echo "<td>" . $row['age'] . "</td> ";
  echo "<td>" . $row['contact'] . "</td>";
  echo "<td>" . $row['address'] . "</td>";
  echo "<td>" . $row['email'] . "</td>";
  echo "<td>" . $row['occupation'] . "</td>";
  echo "</tr>";
}
mysqli_close($connection);
?>

</table>
 </div>
 </table>

通过这种方式,您的表格代码随页面一起加载,并且动态加载数据库中的任何信息

关于php - 无法在 php 中使用 css 设置表格样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41973427/

相关文章:

php - 第一个数据 curl WSDL SSL 失败

php - 如何在 php 中对字符串求和?

html - 如何使 3 列嵌套列表只有内部装订线(没有外部边距)?

css - 媒体查询在一个网站上有效,但在另一个网站上无效

html - 垂直对齐 div 中的内容

html - 指针事件 : none is not working

css - 为什么 YUI Compressor 不最小化带有负单位值的 CSS 规则中的前导零(对于 float )?

php - $wpdb->insert() 不会在表中插入记录

php - 使用PHP向MySQL表添加数据(修订版)

php - Laravel:Eloquent Eager Loading 关系的选择