【问题标题】:HTML/PHP - table cell delimited widthHTML/PHP - 表格单元格分隔宽度
【发布时间】:2014-10-03 06:08:41
【问题描述】:

我有这张桌子

<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>";
        }

}

我认为我在回声中的引用可能有问题,谢谢

【问题讨论】:

    标签: php html html-table


    【解决方案1】:

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

    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>";
        }
    }
    

    关于样式表,最好将它们放在单独的文档中,但您可以使用&lt;style&gt; 标签将样式信息嵌入到 HTML 页面的 &lt;head&gt; 中。这是您正在使用的表格样式的示例:

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

    【讨论】:

    • 这样可以节省时间,谢谢!但是如何实现宽度问题?非常感谢您的帮助
    • 我加了,但是还是生成了一个大表,不知道是什么问题
    • pastebin.com/5zVC3NbF 就是代码比较少,只是排除了mysql连接等一些功能
    • 忘记添加打印功能,现在应该可以了
    • 我复制/粘贴了您的新 html 代码以及 printResultI 函数,这就是输出的样子 dropbox.com/s/u0ompucgxla50gd/wide-table.png?dl=0
    【解决方案2】:

    试试这样的

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

    【讨论】:

    • 好的,我尝试使用“.$variable[]”。但它仍然会产生更长的桌子
    猜你喜欢
    • 1970-01-01
    • 2014-01-01
    • 1970-01-01
    • 2012-07-20
    • 2014-09-11
    • 2021-10-26
    • 1970-01-01
    • 2013-04-26
    • 2012-06-15
    相关资源
    最近更新 更多