【问题标题】:I want to create a table in html with respect to the no.of rows and no.of columns entered by user我想根据用户输入的行数和列数在 html 中创建一个表
【发布时间】:2015-10-31 23:12:59
【问题描述】:

我想根据用户输入的行数和列数在 html 中创建一个表..

任何人都可以通过提供代码来帮助我...

【问题讨论】:

标签: php html css


【解决方案1】:

为了将来参考,我建议您包含您尝试过的代码 sn-p;不仅如此我们可以提供进一步的帮助,而且还将进一步有益于您的知识。

我很快完成了一些代码,它未经测试,如果它不起作用,我深表歉意。下面的代码假设已经提交了一个表单,并且已经设置了一个带有行名称的变量,另一个将 cols。

<?php
$rows = isset($_POST["rows"]) ? $_POST["rows"] : 0; // get the number of rows submitted
$cols = isset($_POST["cols"]) ? $_POST["cols"] : 0; // get the number of cols submitted
?>
<!DOCTYPE html>
<html>
<body>
    <table>
    <?php
    // begin to create the table - rows first
    for ($row = 0; $row < $rows; $row++) { ?>
        <tr>
        <?php for ($col = 0; $col < $cols; $col++) { ?>
            <td></td>
        <?php } // end cols for loop ?>
        </tr>
    <?php } // end rows for loop ?>
    </table>
</body>
</html>

我希望我已经正确理解了这个问题,并且这个答案很有帮助。

【讨论】:

    猜你喜欢
    • 2021-08-20
    • 2015-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多