Dinamik sonrası değerleri Retreiving

2 Cevap

I am using tiny table with some input fields for posting in a page. I want to retrieve the data which the user fills up for a particular instrument number.

Benim kod

<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>

Print_r komutu çıkışlar

Array
(
[txtDateDeposited_57] => 2010-05-07
[txtBankName_57] => pnb
[txtSlipNo_57] => 121
[txtPaymentInstrumentNo_57] => 57
[btnSubmit1] => Submit
[txtDateDeposited_51] => 
[txtBankName_51] => 
[txtSlipNo_51] => 
[txtPaymentInstrumentNo_51] => 51
[txtDateDeposited_52] => 
[txtBankName_52] => 
[txtSlipNo_52] => 
[txtPaymentInstrumentNo_52] => 52
[txtDateDeposited_45] => 
[txtBankName_45] => 
[txtSlipNo_45] => 
[txtPaymentInstrumentNo_45] => 45
[txtDateDeposited_47] => 
[txtBankName_47] => 
[txtSlipNo_47] => 
[txtPaymentInstrumentNo_47] => 47
)

Ben o değerleri girmiş 57 olduğu için id değerleri almak istiyorum. Ama bu value.I dinamik yapmak istiyorum almak için mantığını oluşturmak için kuramıyorum.

Bana bu konuda yardımcı olun.

Teşekkürler

2 Cevap

Kullan explode. Örneğin:

foreach ($POST AS $key => $value) {
    if (strpos ($key, '_') !== false) {
        list($field, $id) = explode ('_', $key, 2);

        if ($value) {
            var_dump ($field, $id, $value);
        }
    }
}

Ya da kimliği biliyorsanız:

var_dump ($_POST['txtPaymentInstrumentNo_'.$Id]);

Edit

Basit kod. notJim thx.

Ben dizi gösterimini kullanarak giriş adları biçimlendirmek olacaktır:

 <td><input type="text"  name="txtDateDeposited[<?php echo $paymentdeposited[pk_paymentinstrumentid];?>]"  class="field date-pick"/></td> 

Lütfen çıkan veri olarak erişilebilir olsun diye

$_REQUEST['txtDateDeposited']['57']

güncelleme:

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
}

Eğer sadece o zaman, BİR çizgi kullandığınızdan emin iseniz:

 foreach( $_POST as $key => $value) {
        $keyPieces = explode("_", $key);
        $field = $keyPieces[0];
        $id = $keyPieces[1];
        // txtDateDeposited_57 becomes
        //  $id -> 57
        //  $field -> txtDateDeposited
    }

çok çalışmak olacaktır.

I [0] yerine dizi sayma $ parçaları yapmak, böylece ilk sayı / tanımlayıcı koyarak daha iyi buluyorum yukarıdaki yöntemi kullanarak herhangi bir şey için, unutmayın. Ayrıca, ($ adet 1) array_slice tekrar ek sayımı olmadan sizin için dışarı alacak.