用于循环的扭曲表

时间:2014-10-06 22:12:59

标签: php html for-loop html-table

我在这张桌子上遇到了麻烦。我需要for循环生成的每一行也生成一个新单元格(不能上传截图),每次循环迭代都会生成太多位于表格右侧的单元格。我该如何解决?感谢

            <?php
                $maxsize = ini_get("upload_max_filesize");
                $firstrow = <<<firstrow
                    <TABLE class="table2" align="center">
                        <TR>
                        <TH scope="row">

                            Puoi caricare massimo 5 file per volta <br> Dimensione massima per file: {$maxsize} 
                        <TD>    
                            <form enctype="multipart/form-data" method="POST">
                                <select name="opzioni">
                                    <option value="1">1</option>
                                    <option value="2">2</option>
                                    <option value="3">3</option>
                                    <option value="4">4</option>
                                    <option value="5">5</option>
                                </select>
                                <input type="submit" value="Invio">
                            </form>
                        </TD>
                        </TR>
firstrow;
echo $firstrow;

if (isset($_POST['opzioni'])) {
$openform  = '<form enctype="multipart/form-data" action="fileinfo.php" method="POST">' . "\r\n";
$closeform = <<<form
<input type="submit" value="Invio">
</form><br>
form;
$opz       = $_POST['opzioni'];

echo $openform;

for ($i = 0; $i < $opz; $i++) {
echo '<TR>';
    echo '<TH scope="row">';
    echo '<input name="doc' . $i . '" type="file"><br />' . "\r\n";
    echo '<TD rowspan="'.$i.'">';
    echo $closeform;
    echo '</TD>';
echo '</TR>';

}
}

            echo '</TABLE>';
                ?>

这是fileinfo.php代码

<?php

    $max_file_size=ini_get("upload_max_filesize");
$mult=strtolower(substr($max_file_size,strlen($max_file_size)-1));
$val=strtolower(substr($max_file_size,0,strlen($max_file_size)-1));
$max_file_size=$val;
switch($mult){
case 'g':
$max_file_size*=1024;
case 'm':
$max_file_size*=1024;
case 'k':
$max_file_size*=1024;
}

$infotxt = <<<infotxt
    <TABLE class="table1" align="center">
    <TR><th scope="row">Scaricare file .txt contenente le info?<TD><form method="POST">    <input type="submit" value="Download" name="downloadtxt"></form></TD></TR>
    <TR><th scope="row">Ricevere file .txt contenente le info via email?<TD><form method="POST" action="mail.php">Inserisci email <input type="text" name="tomail"><input type="submit" value="Invia Email"></form></TD></TR>
    </TABLE>
infotxt;
echo $infotxt.'<br>';


foreach($_FILES as $k=>$v)
{
if (isset($_FILES[$k]) && $_FILES[$k]['error'] == 0) {
$_SESSION['pastepath'] = 'uploads/' .$_FILES[$k]['name'];
if ($_FILES[$k]['size'] > $max_file_size) {
    echo $_FILES[$k]['size'].' &egrave; troppo grande';
}
else
{
    $_SESSION['nomefile']     = $_FILES[$k]['name'];
    $_SESSION['size']     = $_FILES[$k]['size'] / 1000;
    $_SESSION['tipo']     = $_FILES[$k]['type'];
    $_SESSION['dataupload']     = date("d/M/Y H:i:s O");
    require_once 'formato.php';
    $_SESSION['descrtipo'] = descmime($_SESSION['tipo']);
    $info      = <<<info
<TABLE class="table1" align="center">
<TR><th scope="row">Nome originale:<TD>{$_SESSION['nomefile']}</TD></TR>
<TR><th scope="row">Dimensione:<TD>{$_SESSION['size']} kB</TD></TR>
<TR><th scope="row">Tipo MIME:<TD>{$_SESSION['tipo']}</TD></TR>
<TR><th scope="row">Data e ora caricamento:<TD>{$_SESSION['dataupload']}</TD></TR>
<TR><th scope="row">Programma da utilizzare:<TD>{$_SESSION['descrtipo']}</TD></TR>
<TR><th scope="row">Rinomina file e scarica<TD><form method="POST">Inserisci il nuovo nome <input type="text" name="newname"><input type="submit" value="Download"></form>  </TD></TR>
</TABLE>
info;
    echo $info.'<br>';


    if (isset($_FILES['tomail']))
    $_SESSION['tomail'] = $_FILES['tomail'];
    if (isset($_FILES['newname']))
    $_SESSION['newname'] = $_FILES['newname'];

} 

}
        else
        echo 'Nessun file caricato';
}
?>

1 个答案:

答案 0 :(得分:0)

以下是正确的表格设计示例。

&#13;
&#13;
table, td, th {
    border: 1px solid green;
    width: 250px;
}

th {
    background-color: green;
    color: white;
}

td:first-child {
    background-color: green;
    color: white;
}

td {
    padding: 5px; 
}
&#13;
<table>
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
</table>
&#13;
&#13;
&#13;