问题描述
大家好我的问题是这个,我动态地在用户输入的基础上创建表的行。现在每行都包含文本框,comboxbox从组合框中选择值n从前三列的文本框中输入值,结果将显示。在下一页中将所选的n个输入值传递给下一页时,只有最后一行值移动到下一页.i想要传递所有循环值到下一页
javascripting code
hi everyone my problem is this that i dynamically creted rows of table on the basis user input. Now each row contain textbox,comboxbox on selcting value from combobox n entering value in textbox from first three column ,result will display.on passing these selected n entered value on next page only the last row values moves to next page .i want to pass all loop values to next pagejavascripting code
<script>
function getText3(row){
var in1=document.getElementById('in1-' + row).value;
var in2=document.getElementById('in2-' + row).value;
var in4=document.getElementById('in4-' + row).value;
var in3=(in1*in2*in4*30)/1000;
document.getElementById('in3-' + row).value=in3.toFixed(2 );
}
</script>
表格代码
table code
<?php
$de=$_POST['text123'];
echo $de;
?>
<body>
<form action="kl2.php" method="post" >
<table border="1" align="center" id="wr123">
<tr>
<th>WAS</th>
<th>NO.</th>
<th>AVERAGE</th>
<th>APPROX</th>
</tr>
<?php
for ($i = 1; $i <= $de; $i++) {
?>
<tr>
<td>Tube</td>
<td>
<select id="in4-<?php echo $i; ?>" name="t1" onclick="getText3(<?php echo $i; ?>)" >
<option value="0">0</option>
<option value="12">12</option>
<option value="18">18</option>
<option value="24">24</option>
<option value="75">75</option>
</select>
</td>
<td>
<input type="text" name="t2" id="in1-<?php echo $i; ?>" onblur="getText3(<?php echo $i; ?>)" />
</td>
<td>
<select name="a1" id="in2-<?php echo $i; ?>" onclick="getText3(<?php echo $i; ?>)" >
<option value="0">0</option>
<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>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
</select>
</td>
<td>
<input type="text" id="in3-<?php echo $i; ?>" name="username" readonly="readonly" />
</td>
<td>
</tr>
<?php } ?>
<input type="submit" name="submit" />
</table>
</form>
kl2.php
<?php
@$a=$_POST['t1'];
echo @$a;
$sl = $_POST['t2'];
echo $sl;
$b=$_POST['a1'];
echo $b;
$c=$_POST['username'];
echo $c;
?>
在提交时点击它只显示最后一行值,即如果用户输入3,3行后显示点击仅提交最后一行显示的数据
on submit click it only display the last row values i.e if user enter 3 ,3 rows get displayed after clicking the submit only the data of last row display
推荐答案
您需要传递一个数组,您可以将其作为数组在PHP端。
You need to be passing an array, you can deal with it as an array in the PHP side.
为此,在每个输入中,将name =X更改为name =X []
To do this, in each input, change the name="X" to name="X[]"
Example:
<input type="text" name="t2" id="in1-<?php echo $i; ?>" onblur="getText3(<?php echo $i; ?>)" />
到:
<input type="text" name="t2[<?php echo $i; ?>]" id="in1-<?php echo $i; ?>" onblur="getText3(<?php echo $i; ?>)" />
另外,在php中使用@来抑制错误通常是个坏主意。
Also, it's generally a bad idea to use @'s in php to suppress errors.
试试类似:
Try something like:
var_dump($_POST);
,您将看到数据如何传递给您。
and you will see how the data comes through to you.
提示:
Hint:
if (isset($_POST['t1']) {
$t1_data = $_POST['t1'];
}
**编辑**
试试这样:
Try something like this:
<?php
if (isset($_POST['submit'])) {
$data_t1 = $_POST['t1'];
foreach ($data_t1 as $key => $value) {
echo 'T1: ' . $value . '<br />';
echo 'T2: ' . $_POST['t2'][$key] . '<br />';
echo 'Username: ' . $_POST['username'][$key] . '<br /><br />';
}
}
?>
<html>
<head>
<script>
function getText3(row){
var in1=document.getElementById('in1-' + row).value;
var in2=document.getElementById('in2-' + row).value;
var in4=document.getElementById('in4-' + row).value;
var in3=(in1*in2*in4*30)/1000;
document.getElementById('in3-' + row).value=in3.toFixed(2 );
}
</script>
</head>
<body>
<form action="" method="POST">
<table border="1" align="center" id="wr123">
<tr>
<th>WAS</th>
<th>NO.</th>
<th>AVERAGE</th>
<th>APPROX</th>
</tr>
<?php
for ($i = 1; $i < 4; $i++) {
?>
<tr>
<td>Tube</td>
<td>
<select id="in4-<?php echo $i; ?>" name="t1[<?php echo $i; ?>] onclick="getText3(<?php echo $i; ?>)" >
<option value="0">0</option>
<option value="12">12</option>
<option value="18">18</option>
<option value="24">24</option>
<option value="75">75</option>
</select>
</td>
<td>
<input type="text" name="t2[<?php echo $i; ?>]" id="in1-<?php echo $i; ?>" onblur="getText3(<?php echo $i; ?>)" />
</td>
<td>
<select name="a1[<?php echo $i; ?>]" id="in2-<?php echo $i; ?>" onclick="getText3(<?php echo $i; ?>)" >
<option value="0">0</option>
<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>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
</select>
</td>
<td>
<input type="text" id="in3-<?php echo $i; ?>" name="username[<?php echo $i; ?>]" readonly="readonly" />
</td>
<td>
</tr>
<?php } ?>
</table>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
这篇关于如何在PHP中将循环的值从一页传递到下一页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!