Php 检索动态post值
我使用带有一些输入字段的小表格在页面中发布。 我想检索用户为特定仪器编号填写的数据 我的代码Php 检索动态post值,php,Php,我使用带有一些输入字段的小表格在页面中发布。 我想检索用户为特定仪器编号填写的数据 我的代码 <form name="frmDeposit" action="paymentdeposited.php" method="post"> <table cellpadding="0" cellspacing="0" border="0" id="table" class="tinytable" style="width:700px;"> <thead
<form name="frmDeposit" action="paymentdeposited.php" method="post">
<table cellpadding="0" cellspacing="0" border="0" id="table" class="tinytable" style="width:700px;">
<thead>
<tr>
<th><h3>Email</h3></th>
<th><h3>Amount Paid</h3></th>
<th><h3>Instrument Type</h3></th>
<th><h3>Instrument No.</h3></th>
<th><h3>Date Paid</h3></th>
<th class="nosort"><h3>Date Deposited</h3></th>
<th class="nosort"><h3>Bank Name</h3></th>
<th class="nosort"><h3>Slip No.</h3></th>
<th class="nosort"><h3>Submit</h3></th>
</tr>
</thead>
<tbody>
<?php
foreach($paymentsdeposited as $paymentdeposited)
{
?>
<tr>
<td><?php echo $paymentdeposited[email];?></td>
<td><?php echo $paymentdeposited[amount];?></td>
<td><?php echo $paymentdeposited[instrument];?></td>
<td><?php echo $paymentdeposited[instrumentnumber];?></td>
<td><?php echo $paymentdeposited[dated];?></td>
<td><input type="text" name="txtDateDeposited_<?php echo $paymentdeposited[pk_paymentinstrumentid];?>" class="field date-pick"/></td>
<td><input type="text" name="txtBankName_<?php echo $paymentdeposited[pk_paymentinstrumentid];?>" class="field"/></td>
<td><input type="text" name="txtSlipNo_<?php echo $paymentdeposited[pk_paymentinstrumentid];?>" class="field"/><input type="hidden" name="txtPaymentInstrumentNo_<?php echo $paymentdeposited[pk_paymentinstrumentid];?>" value="<?php echo $paymentdeposited[pk_paymentinstrumentid];?>" class="field"/></td>
<td><input type="submit" name="btnSubmit1" value="Submit"/></td>
</tr>
<?php
}
?>
</tbody>
</table>
我想检索id 57的值,他为其输入了值。但我无法构造检索此值的逻辑。我想让它成为动态的。我会使用数组符号格式化您的输入名称:
<td><input type="text" name="txtDateDeposited[<?php echo $paymentdeposited[pk_paymentinstrumentid];?>]" class="field date-pick"/></td>
更新:
foreach( $_POST as $key => $value) {
$keyPieces = explode("_", $key);
$field = implode("_", array_slice( $keyPieces, 0, count($keyPieces)-1 ));
$id = $keyPieces[count($keyPieces)-1];
// txtDateDeposited_57 becomes
// $id -> 57
// $field -> txtDateDeposited
}
如果确定只使用一个下划线,则:
foreach( $_POST as $key => $value) {
$keyPieces = explode("_", $key);
$field = $keyPieces[0];
$id = $keyPieces[1];
// txtDateDeposited_57 becomes
// $id -> 57
// $field -> txtDateDeposited
}
这也行
注意,对于使用上述方法的任何操作,我发现将数字/标识符放在第一位更好,这样您就可以执行$pieces[0],而不是计算数组。另外,您的数组片($pieces,1)将为您取出它,而不再进行额外计数。我将使用数组符号格式化您的输入名称:
<td><input type="text" name="txtDateDeposited[<?php echo $paymentdeposited[pk_paymentinstrumentid];?>]" class="field date-pick"/></td>
更新:
foreach( $_POST as $key => $value) {
$keyPieces = explode("_", $key);
$field = implode("_", array_slice( $keyPieces, 0, count($keyPieces)-1 ));
$id = $keyPieces[count($keyPieces)-1];
// txtDateDeposited_57 becomes
// $id -> 57
// $field -> txtDateDeposited
}
如果确定只使用一个下划线,则:
foreach( $_POST as $key => $value) {
$keyPieces = explode("_", $key);
$field = $keyPieces[0];
$id = $keyPieces[1];
// txtDateDeposited_57 becomes
// $id -> 57
// $field -> txtDateDeposited
}
这也行
注意,对于使用上述方法的任何操作,我发现将数字/标识符放在第一位更好,这样您就可以执行$pieces[0],而不是计算数组。另外,您的阵列片($pieces,1)将为您取出,而无需再次进行额外计数。使用。例如:
或者如果你知道身份证:
var_dump ($_POST['txtPaymentInstrumentNo_'.$Id]);
编辑
更简单的代码。thx给notJim。使用。例如:
或者如果你知道身份证:
var_dump ($_POST['txtPaymentInstrumentNo_'.$Id]);
编辑
更简单的代码。thx致notJim。您好,谢谢,但此$_请求['txtdateDeposted']['57']是静态的,我想使其成为动态的。我想根据用户为特定仪器所做的输入更新表格。代码将提供所有id,但我需要他为其输入的id。Hi dan谢谢,但此$_请求['TXTDateDeposted']['57']是静态的,我想使其成为动态的。我想根据用户为特定仪器输入的项更新表。代码将提供所有id,但我需要他为其输入的id。我认为您需要
分解(“”,$key,2)
作为最后一个参数指定返回数组中的元素数。您可以使用list($field,$id)=分解(“”,$key,1)代码>以避免$tmp
,供参考。最好确保下划线先存在!我想根据用户为特定仪器所做的输入更新一个表。代码会给我所有的id,但我想要的是他输入的id。我检查$value是否足够?@piotr以下代码是否正确。foreach($_postas$key=>$value){if(strpos($key,)!==false){list($field,$id)=explode(''$key,2);if($value!=''){if($field=='txtdatedeposition'){$date value;$instrumentid=$id;}if($field='txtBankName')$bank=$value;if($field=='txtSlipNo'))$slip=$value;}}}}echo$date.'
'.$bank.'
'.$slip.
'.$instrumentid;看起来不错。你应该知道你是否在回音中看到了正确的值。我想你想要分解('''',$key,2)
作为最后一个参数指定返回数组中的元素数。您可以使用list($field,$id)=分解(“”,$key,1)代码>以避免$tmp
,供参考。最好确保下划线先存在!我想根据用户为特定仪器所做的输入更新一个表。代码会给我所有的id,但我想要的是他输入的id。我检查$value是否足够?@piotr以下代码是否正确。foreach($_postas$key=>$value){if(strpos($key,)!==false){list($field,$id)=explode(''$key,2);if($value!=''){if($field=='txtdatedeposition'){$date value;$instrumentid=$id;}if($field='txtBankName')$bank=$value;if($field=='txtSlipNo'))$slip=$value;}}}}echo$date.'
'.$bank.'
'.$slip.
'.$instrumentid;看起来不错。您应该知道在回音中是否看到正确的值。