HTML/PHP-表格单元格分隔宽度


HTML/PHP - table cell delimited width

我有这个表

<table name='test'border='1' style='width: 100%'>
    <tr>
        <th valign='top' style='width: 9%'>No.</th>
        <th valign='top' style='width: 9%'>Epitope/Cluster Sequence:</th>
        <th valign='top' style='width: 9%'>Epitope ID:</th>
        <th valign='top' style='width: 9%'>Source Organism</th>
        <th valign='top' style='width: 9%'>Source Protein:</th>
        <th valign='top' style='width: 9%'>MHC Restriction:</th>
        <th valign='top' style='width: 9%'>RF Score:</th>
        <th valign='top' style='width: 9%'>Assay Score:</th>
        <th valign='top' style='width: 9%'>Assay Type:</th>
        <th valign='top' style='width: 9%'>Effector Origin:</th>
        <th valign='top' style='width: 9%'>Reference ID:</th>
    </tr>

我想添加更多的行并保持相同的宽度,当我只使用第一行测试时,带分隔符有效,但当添加新行时,它不起作用,我添加新行的代码是:

function printResultI($array)
{
    $i=0;
    foreach($array as $row) {
        $i=$i+1;
        echo" 
        <tr>
            <td style='width: 9%'>$i</td>
            <td style='width: 9%'>$row[linear_sequence]</td>
            <td style='width: 9%'>$row[E_ID]</td>
            <td style='width: 9%'>$row[ant_source_organism_name]</td>
            <td style='width: 9%'>$row[E_OBJECT_SOURCE_NAME]</td>
            <td style='width: 9%'>$row[mhc_restriction]</td>
            <td style='width: 9%'>$row[RFS]</td>
            <td style='width: 9%'>$row[assay_score]</td>
            <td style='width: 9%'>$row[AS_TYPE]</td>
            <td style='width: 9%'>$row[effector_origin]</td>
            <td style='width: 9%'>$row[unique_reference_id]</td>
        </tr>";
        }
}

我认为我在echo中的报价可能有问题,谢谢

您可以通过设置样式表来处理所有样式信息(宽度、边框等)来节省大量时间和打字。您还可以使用以下编码样式简化输出:

function printResultI($array)
{
    # make an array of the pieces of information from $row that you want to get
    $cols = array( 'linear_sequence', 'E_ID', 'ant_source_organism_name',
        'E_OBJECT_SOURCE_NAME', 'mhc_restriction', 'RFS', 'assay_score', 'AS_TYPE',
        'effector_origin', 'unique_reference_id');
    $i=0;
    foreach($array as $row) {
        $i=$i+1;
        echo "<tr><td>$i</td>";
        # now go through the array and get the appropriate data.
        foreach ($cols as $c) {
            echo "<td>" . $row[$c] . "</td>";
        }
        echo "</tr>";
    }
}

关于样式表,最好将它们放在单独的文档中,但可以使用<style>标记将样式信息嵌入HTML页面的<head>中。以下是您使用的表格样式示例:

<head>
    <title>Document title here!</title>
    <style type="text/css">
    table {
        border: 1px solid #000;  /* solid black border */
        width: 100%;
    }
    th, td {
        width: 9%; /* sets all td and th elements to width 9% */
    }
    th {
        vertical-align: top;
    }
    </style>
</head>

尝试类似的东西

<td style='width: 9%'>".$row[linear_sequence]."</td>