无法在php中使用css样式表

I am unable to style the table in css even though i have insert style for the tables.

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

The above is a simple style for the codes

<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>

The above is for displaying the tables. May i know what i can do so that it displays the table with the css. Thanks.

duane2364
duane2364 你有一个表标签内的表标签。去掉它
3 年多之前 回复
doushi1900
doushi1900 哪个表标签?
3 年多之前 回复
duanpang2751
duanpang2751 你有一个错误的HTML结构。删除其中一个表标记
3 年多之前 回复
doulu3399
doulu3399 尝试向样式定义添加背景,因为表中的边框不能正常工作
3 年多之前 回复

2个回答

Its because your inserting the table dynamically with php.

try this

<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>

This way your table code is loaded with the page, and any information from the database is dynamically loaded

You can style easily. echo of html is bad practice. so kidly check the below way.

<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)){ ?>
 <tr>
   <td><?php echo $row['Username']; ?></td>
   <td><?php echo $row['password']; ?></td>
   <td><?php echo $row['Name']; ?></td>
   <td><?php echo $row['gender']; ?></td>
   <td><?php echo $row['age']; ?></td>
   <td><?php echo $row['contact']; ?></td>
   <td><?php echo $row['address']; ?></td>
   <td><?php echo $row['email']; ?></td>
   <td><?php echo $row['occupation']; ?></td>
 </tr>
<?php } ?>
</table>
<?php mysqli_close($connection); ?>
?>

and in CSS you can use as before.

table, th, td { border: 1px solid black; }

Hope this will help you!!!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐