如何附加外部CSS文件以显示从MySQL数据库获取的数据?我可以使用CSS而不是表格来显示数据。我想完全避免表格显示提取的数据。

这是从MySQL数据库获取数据的代码:

<?php
echo "Database Date: " .date("Y-m-d");
?>


此数据中包含的变量包括:分配的NCL编号,医院,年龄,性别,原发癌以及患者的诊断日期和最新治疗方法。

<style type="text/css">
  table.data { width:100%;  margin: 0;
      border: 1px solid black; border-spacing: 2px; }
  .id {width: 7%; background-color: #c7c7c0; }
  .date {width: 12%; background-color: #d8d8d1; }
  .nclnumber { width: 10%; background-color: #c7c7c0; }
  .hospital {width: 17%; background-color: #d8d8d1; }
  .age { width: 3%; background-color: #c7c7c0; }
  .sex { width: 2%; background-color: #d8d8d1; }
  .cancer { width: 10%; background-color: #d8d8d1; }
  .dateofdiagnosis { width: 7%; background-color: #d8d8d1; }
  .notes { width: 32%; background-color: #d8d8d1; }
</style>

<table class="data" border="0" cellspacing="2">
  <tr>
    <td class="id"><b>Id</b></td>
    <td class="date"><b>Date</b></td>
    <td class="nclnumber"><b>NCL Number</b></td>
    <td class="hospital"><b>Hospital</b></td>
    <td class="age"><b>Age</b></td>
    <td class="sex"><b>Sex</b></td>
    <td class="cancer"><b>Diagnosed Cancer</b></td>
    <td class="dateofdiagnosis"><b>Date of Diagnosis</b></td>
    <td class="notes"><b>Notes</b></td>
   </tr>
 </table>


<?php
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error());
 mysql_select_db("cancer") or die(mysql_error());
 $data = mysql_query("SELECT * FROM cancer WHERE Age ='1'OR Age = '2' OR Age = '3'OR Age = '4'OR Age = '5'OR Age = '6'OR Age = '7'OR Age = '8'OR Age = '9'")
 or die(mysql_error());


while($info = mysql_fetch_array( $data )) {
  echo "<table class='data' border='0' cellspacing='2'>
          <tr>
            <td class='id'>".$info['Id']."</td>
            <td class='date'>".$info['Date']."</td>
            <td class='nclnumber'>".$info['NCL_Number']."</td>
            <td class='hospital'>".$info['Hospital']."</td>
            <td class='age'>".$info['Age']."</td>
            <td class='sex'>".$info['Sex']."</td>
            <td class='cancer'>".$info['Diagnosed_Cancer']."</td>
            <td class='dateofdiagnosis'>".$info['Date_of_Diagnosis']."</td>
            <td class='notes'>".$info['Notes']."</td>
          </tr>
        </table>";
  }
?>

最佳答案

绝对没有理由不对表格数据使用<table>元素。

某些人的反表歇斯底里只是一个误解:将表误用于布局目的是不好的。不过,HTML标记没有错。实际上,使用任何其他HTML元素显示表格数据对语义都是不利的。

<table>标记及其包含的<tr>行和<td>列通知浏览器,使其呈现相关数据且为列状。不要将<table>(或与此相关的任何HTML标记)严格地视为视觉显示元素。它们将有关数据的含义传达给正在解析的机器。

09-27 07:37
查看更多