我有一个使用PHP中的$ _GET将数据传输到另一个页面的表单。在另一个页面的浏览器中,它显示了导出的所有数据,但是当它进入页面时,它只显示第一行。我还希望能够只导出选定的字段。
以下是我的代码,
<?php do { ?>
<form action="../masspay/index.php" name="pile" method="GET" >
<tr>
<td><input type="checkbox" name="checkbox" value="check" /></td>
<td><input name="id" type="text" id="id" value="<?php echo $row_pile['id']; ?>" size="10" /></td>
<td><input name="amount" type="text" id="amount" value="<?php echo $row_pile['amount']; ?>" size="10" /></td>
<td><input name="amtnaira" type="text" id="amtnaira" value="<?php echo $row_pile['amtnaira']; ?>" size="13" /></td>
<td><input name="acctno1" type="text" id="acctno1" value="<?php echo $row_pile['acctno1']; ?>" size="10" />
(<?php echo $row_pile['accountname']; ?>)</td>
<td><input name="phone" type="text" id="phone" value="<?php echo $row_pile['phone']; ?>" size="13" /></td>
<td><input name="staff" type="text" id="staff" value="<?php echo $row_admin['name']; ?>" size="15" /></td>
<tr>
<?php } while ($row_pile = mysql_fetch_assoc($pile)); ?>
<td colspan="7"><input type="submit" name="Submit" value="Process Selected" /></td>
</tr>
</form>
答案 0 :(得分:0)
kk看起来你有一个数据库,你从中获取值并将其显示在文本框的值中。要发送值,你必须在index.php页面上捕获它们 通过做
$_GET['id']
$_GET['name'] and furthor
now for selected field set the value on the other page check the value of checkbox that it is checked or unchecked by assinging a variable
答案 1 :(得分:0)
为什么要发送这样的数据? session可能是更好的选择。
无论如何,如果sql有多个结果,则先前的_GET
值将被覆盖。
试试这个:
<?php do { ?>
<form action="../masspay/index.php" name="pile" method="GET" >
<tr>
<td><input type="checkbox" name="checkbox[]" value="check" /></td>
<td><input name="id[]" type="text" id="id" value="<?php echo $row_pile['id']; ?>" size="10" /></td>
<td><input name="amount[]" type="text" id="amount" value="<?php echo $row_pile['amount']; ?>" size="10" /></td>
<td><input name="amtnaira[]" type="text" id="amtnaira" value="<?php echo $row_pile['amtnaira']; ?>" size="13" /></td>
<td><input name="acctno1[]" type="text" id="acctno1" value="<?php echo $row_pile['acctno1']; ?>" size="10" />
(<?php echo $row_pile['accountname']; ?>)</td>
<td><input name="phone[]" type="text" id="phone" value="<?php echo $row_pile['phone']; ?>" size="13" /></td>
<td><input name="staff[]" type="text" id="staff" value="<?php echo $row_admin['name']; ?>" size="15" /></td>
<tr>
<?php } while ($row_pile = mysql_fetch_assoc($pile)); ?>
<td colspan="7"><input type="submit" name="Submit" value="Process Selected" /></td>
</tr>
</form>
$_GET['id']
,$_GET['amount']
等的结果现在将是一个数组并包含所有sql结果。
由于我不知道你在接收页面上做了什么,我正在使用print_r
,以便你可以看到数据的结构:
echo '<pre>'; // easier to read in a browser
echo 'Dump of checkbox: <br/>';
print_r($_GET['checkbox']);
echo 'Dump of id: <br/>';
print_r($_GET['id']);
echo 'Dump of amount: <br/>';
print_r($_GET['amount']);
echo 'Dump of acctno1: <br/>';
print_r($_GET['acctno1']);
etc ...
echo '</pre>';
示例输出:
Dump of checkbox:
array(
0 => 'check', // id 1 has been checked
1 => '', // id 2 has not been checked
),
Dump of id:
array(
0 => 1, // id 1
1 => 2, // id 2
),
Dump of amount:
array(
0 => amount for id 1,
1 => amount for id 2,
)
Dump of acctno1:
array(
0 => acctno1 for id 1
1 => acctno1 for id 2
)
etc ...
检查是否勾选了复选框:
// will return checked
if ($_GET['checkbox'][0] == 'check') {
echo 'checked';
} else {
echo 'not checked';
}
//will return not checked
if ($_GET['checkbox'][3] == 'check') {
echo 'checked';
} else {
echo 'not checked';
}
评论更新:
$tt = ''.
foreach ($_GET['id'] as $key => $id) {
$tt .= "$_GET['acctno1'][$key], $_GET['amount'][$key], not-private, order #$id. www.xxx.com, we hope to serve you often.<br/>";
}
echo $tt;
答案 2 :(得分:0)
由于您只需要选择在接收页面上显示哪些结果,因此这是一种更好,更安全的方法:
<form action="../masspay/index.php" name="pile" method="GET" >
<tr>
<?php while ($row_pile = mysql_fetch_assoc($pile)) { ?>
<td><input type="checkbox" name="checked[]" value="<?php echo $row_pile['id']; ?>" /></td>
<td><?php echo $row_pile['id']; ?></td>
<td><?php echo $row_pile['amount']; ?></td>
<td><?php echo $row_pile['amtnaira']; ?></td>
<td><?php echo $row_pile['acctno1']; ?>(<?php echo $row_pile['accountname']; ?>)</td>
<td><?php echo $row_pile['phone']; ?>></td>
<td><?php echo $row_admin['name']; ?></td>
<?php } ?>
<td colspan="7"><input type="submit" name="Submit" value="Process Selected" /></td>
</tr>
</form>
在接收页面上:
if (empty($_GET['checked']) {
echo 'No results';
} else {
$ids = array();
foreach ($_GET['checked'] as $checked) {
settype($checked, 'integer');
$ids[] = "id = $id";
}
//Modify the sql used for the form to add this WHERE:
$sql = 'SELECT * FROM table WHERE ' . implode(' OR ', $ids);
$pile = mysql_query($sql);
while ($row_pile = mysql_fetch_assoc($pile)) {
echo "$row_pile['acctno1'] $row_pile['amount'], not-private, order #$row_pile['id'];. www.xxx.com, we hope to serve you often.<br/>";
}
}