douweng1935 2014-10-02 21:40
浏览 43
已采纳

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

I have this table

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

And I want to add next more rows and keep the same width, the with delimiter works when I test it using only the first row, but it doesn't work when the new rows are added, my code to add the new rows is:

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

}

I think there might be an issue with my quotes inside the echo, thank you

  • 写回答

2条回答 默认 最新

  • dounieyan2036 2014-10-02 22:03
    关注

    You can save yourself a LOT of time and typing by setting up a stylesheet to deal with all the style information--width, borders, etc. You can also simplify your output using the following coding style:

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

    Regarding stylesheets, it is best to have them in a separate document, but you can embed style information in the <head> of an HTML page using the <style> tag. Here's a sample with the table styling you're using:

    <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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?