Php 获取要在一行中显示的复选框和相应的文本字段值
我有一个表单,根据我想要的数字动态生成复选框字段和文本字段。这是表单和生成的字段Php 获取要在一行中显示的复选框和相应的文本字段值,php,html,css,Php,Html,Css,我有一个表单,根据我想要的数字动态生成复选框字段和文本字段。这是表单和生成的字段 <?php $num = "6"; $index = "0"; echo "<form action='".$_SERVER['PHP_SELF']."' name='myform' method='post'>"; echo "<table>"; for($i= 0;$i<$num;$i++){ echo "&l
<?php
$num = "6";
$index = "0";
echo "<form action='".$_SERVER['PHP_SELF']."' name='myform' method='post'>";
echo "<table>";
for($i= 0;$i<$num;$i++){
echo "<tr><td><input type='hidden' name='indexnum[]' value='".$index."'><input type='checkbox' name='mychecks[]' value='check".$i."'><input type='text' name='checktext[]' size='20'></td><tr>";
$index++;
}
echo "<tr><td><input type='submit' name='submit' value='Submit'/></td></tr>";
echo "</table>";
echo "</form>";
if(isset($_POST['submit'])){
$num = count($_POST['indexnum']);
for($i=0;$i<$num;$i++){
$index = $_POST['indexnum'];
$checkvalues = $_POST['mychecks'];
$textValue = $_POST['checktext'];
echo $index[$i].".)".$checkvalues[$i]." coressponse ".$textValue[$i]."<br>";
}
}
?>
您必须访问数组文件。因此,在持有您的解决方案时:
...
$index = $_POST['indexnum'][$i];
$checkvalues = $_POST['mychecks'][$i];
$textValue = $_POST['checktext'][$i];
...
仅需2个输入的解决方案:
<form action='<?php echo $_SERVER['PHP_SELF'];?>' name='myform' method='post'>
<table>
<?php
$num = "6";
for($i= 0;$i<$num;$i++)
{
?>
<tr>
<td>
<input type='checkbox' name='mychecks[<?php echo $i;?>]' value='1'>
<input type='text' name='checktext[<?php echo $i;?>]' size='20'>
</td>
</tr>
<?php
}
?>
<tr><td><input type="submit" name="submit" value="Submit" /></td></tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$i = 1;
foreach ($_POST["mychecks"] as $id=>$val)
{
echo ($i++).".)".$id." coressponse ".$_POST["checktext"][$id]."<br>";
}
}
?>
如果您可以显示当前的html输出,这将很有帮助……您的问题毫无意义。您发布的代码生成了这个。你想让它做什么而不做什么?你问题的标题是对应的文本字段值显示在一行中
,但问题本身与字段的显示方式无关,而是从字段中获取值。(和--1995,他们想要回他们的
布局)