Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HTML/PHP-表格单元格分隔宽度_Php_Html_Html Table - Fatal编程技术网

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

HTML/PHP-表格单元格分隔宽度,php,html,html-table,Php,Html,Html 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=

我有这张桌子

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

不
表位/簇序列:
表位ID:
源生物
来源蛋白:
MHC限制:
RF分数:
化验分数:
分析类型:
效应器来源:
参考ID:
我想添加更多的行并保持相同的宽度,当我仅使用第一行测试时,with分隔符起作用,但添加新行时它不起作用,我添加新行的代码是:

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

}
函数printResultI($array)
{
$i=0;
foreach($array作为$row){
$i=$i+1;
回声“
$i
$row[线性_序列]
$row[E_ID]
$row[蚂蚁源生物名称]
$row[E_对象\源\名称]
$row[mhc_限制]
$row[RFS]
$row[化验分数]
$row[按类型]
$row[效应器\原点]
$row[唯一的\u引用\u id]
";
}
}

我想我在echo中的引用可能有问题,谢谢你尝试这样的方法

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

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

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>";
    }
}
函数printResultI($array)
{
#从$row中创建一个要获取的信息片段数组
$cols=数组('linear_sequence'、'E_ID'、'ant_source_organism_name',
“E_对象来源名称”、“mhc_限制”、“RFS”、“分析评分”、“AS_类型”,
“效应器原点”、“唯一参考id”);
$i=0;
foreach($array作为$row){
$i=$i+1;
回音“$i”;
#现在检查数组并获取适当的数据。
foreach($cols作为$c){
回显“$row[$c]”;
}
回声“;
}
}
关于样式表,最好将它们放在单独的文档中,但是可以使用
标记将样式信息嵌入HTML页面的
中。以下是您正在使用的表格样式示例:

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

文档标题在这里!
桌子{
边框:1px实心#000;/*实心黑色边框*/
宽度:100%;
}
th,td{
宽度:9%;/*将所有td和th元素的宽度设置为9%*/
}
th{
垂直对齐:顶部;
}

好的,我尝试了使用“$variable[]”符号,但它仍然会生成更长的表格,非常节省时间,谢谢!但是如何实现宽度问题呢?我非常感谢您的帮助我添加了它,但它仍然生成了一个大表,不确定是什么问题,代码更少,只是不包括mysql连接和其他一些函数。现在可以添加打印功能了。我复制/粘贴了新的html代码和printResultI函数,这就是输出的样子