使用基于用户输入数据的php创建动态表 [英] Creating a dynamic table using php based on users input data

查看:114
本文介绍了使用基于用户输入数据的php创建动态表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我正在尝试使用PHP创建一个日常的类例程.首先,该站点将具有"7天名称"作为复选框,以及一个文本框,用户可以在其中输入课时编号.

Currently I am trying to create a daily class routine using PHP. Firstly the site will have seven days name as check box and a text box where users could enter number of class period.

当用户提交表单时,代码将在另一个表内创建另一个表单(看起来像).最后,用户可以输入班级名称,老师姓名,然后代码会将其存储在数据库中.

When user will submit the form the code will create another form inside another table (looks like this). And finally user could enter class name, teacher name and the code will store it in database.

但是我的问题是动态创建表.我找不到解决方法.

任何帮助将不胜感激.

在下面,您可以看到到目前为止我已经尝试过的内容:

Below you can see what I have tried so far:

<h1>Form two</h1>

<form action="routine_create_process.php" method="POST">
<h3>How many class period do you want to add?</h3>

<input type="text" name="period"/>

<h3>Avalible class day</h3>

<label><input type="checkbox" name="f[]" value="sat" /> Saturday </label>
<br />
<label><input type="checkbox" name="f[]" value="sun"  /> Sunday </label>
<br />
<label><input type="checkbox" name="f[]"  value="mon" /> Monday </label>
<br />
<label><input type="checkbox" name="f[]"  value="tues" /> Tuesday </label>
<br />
<label><input type="checkbox" name="f[]"  value="thurs" /> Wednesday </label>
<br />
<label><input type="checkbox" name="f[]"  value="thus" /> Thursday </label>
<br />
<label><input type="checkbox" name="f[]"  value="fri" /> Friday </label>
<br />
<input type="submit" value="SUBMIT"/>
</form>

我的PHP代码:

<?php
$period=$_POST['period'];
$arr2=$_POST['f'];
?>

<table border='2'>
<?php 
$count=count($arr2)-1;
for($i=0;$i<=$count;$i++){
  echo "<tr><td>";
  if($i==0){
    echo "<table>";
    echo "<div class='wrap_p'>";
    for($r=1;$r<=$period;$r++){
      echo "<td>";
      echo "<div class='add_css'>";
      echo $r;
      echo "</div></td>";
    }
    echo "</div>";
    echo "</table>";
  }
  echo "</tr><tr><td>"; 
  echo $arr2[$i];
  echo "</td>";
  echo "<td> <input type='text' size='20' /></tr></td>";
}
?>
</table>

推荐答案

这应该可以解决您的问题.

This should solve your problem.

<?php

$arr2=$_POST['f'];
$period = $_POST['period'];

?>

<table border='2'>
<?php 
$count=count($arr2)-1;
?>
<tr><td>&nbsp;</td>
<?php
                for($r=1;$r<=$period;$r++){
                    echo "<td>";
                    echo "<div class='add_css'>";
                    echo $r ;
                    echo "</div></td>";

                }
    for($i=0;$i<=$count;$i++){

echo "<tr><td>"; 

echo $arr2[$i];

        for($r=1;$r<=$period;$r++)
        {
            echo "<td>";
            echo "<div class='add_css'>";
            echo "<input type='text' size='20' />" ;
            echo "</div></td>";
        }

echo "</td>";


}

?>
</table>

这篇关于使用基于用户输入数据的php创建动态表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆