复选框只发送特定的行到php表单解析器 [英] Checkbox to send only specific rows to php form parser

查看:151
本文介绍了复选框只发送特定的行到php表单解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用php来使用表单。

我从数据库填充表单信息。



表单输入分为多行。

表单提供了一个复选框,只传递该行数据应该发生的是当我解析表单解析文档中的数据时,我只能得到被检查的行。然而,发生的情况是复选框数组的$ _POST方法将只返回检查的内容,但所有其他输入数组仍然包含所有行,即使是那些

 <?php 



while ($ row = mysql_fetch_assoc($ query)){
$ id = $ row [id];
$ email = $ row [user_email];
$ androidId = $ row [user_androidid];
$ amount = $ row [amount];

echo'< tr>
< td>< input id ='data_id'name ='data_id []'size = '25'value ='。$ id。 '/>< / td>
< td>< input id ='mail'name ='mail []'size = '25'value ='。$ email。'/> ;< / td>
< td>< input id ='androidId'name ='androidId []'size = '25'value ='。$ androidId。'/>< td>
< td>< input id ='amount'name ='amount []'size = '25'value ='。$ amount。'/>< / td>
< td>即将推出...< / td>
< td><输入ID ='货币'名称='currencyCode []'size = '25'value ='USD'/
< td>< input type ='checkbox'name ='selected [ / TR>中;



}
?>

我正在测试它:

  for($ i = 0; $ i< count($ _ POST [selected]); $ i ++){

echo $ _POST [选择了] [$ i]于; ($ i = 0; $ i< count($ _ POST [mail]); $ i ++){

echo $ _POST [
$ b} 邮件] [$ i];




$ b $ p
$ b

现在有一个具体的例子,我有三行,I 检查第一个和最后一个。

当我解析表单数据时,复选框数组仅返回第一个和最后一个的值,但是如果我尝试解析mail [],则它具有所有值第1,2和3行。



关于如何正确配置这个的任何想法?我确信这个结构有问题,只是寻求确认。尝试将输入数组连接在一起相同的键,在这种情况下 $ id -

  while($ row = mysql_fetch_assoc($ query)){
$ id = $ row [id];
$ email = $ row [user_email];
$ androidId = $ row [user_androidid];
$ amount = $ row [amount];

echo< tr>
< td>< input id ='data_id'name ='data_id [。$ id。]'size = '25'value = ''。$ id。'/>< / td>
< td>< input id ='mail'name ='mail [。$ id。]'size = '25' value ='。$ email。'/>< / td>
< td>< input id ='androidId'name ='androidId [。$ id。]'size =' 25'value ='。$ androidId。'/>< / td>
< td>< input id ='amount'name ='amount [。$ id。]'size = '25'value ='。$ amount。'/>< / td>
< td>即将推出...< / td>
< td><输入id ='currency'name ='currencyCode [。$ id。]'size = '25'value ='USD'/>< / td>
< td>< input type = 'checkbox'name ='selected [。$ id。]'value ='。$ id。'/>< td>
< / tr>;

$ / code>

然后在这篇文章中你只能得到被检查的数组 - ($ _ POST [selected] as $ key => $ value){
echo $ _POST []

  foreach data_id] [$关键] 
echo $ _POST [mail] [$ key];
echo $ _POST [androidId] [$ key];
echo $ _POST [amount] [$ key];
echo $ _POST [currencyCode] [$ key];
echo $ _POST [selected] [$ key];
}


I'm trying to use a form with php.

I populate the form info from a database.

The form input is separated into rows.

The form offers a checkbox to only pass that row of data and what is supposed to happen is when I parse the data in the form parsing document I only get the rows that were checked.

However what's happening is that the $_POST method for the checkbox array will only return what's checked, but all the other input arrays still contain all the rows, even the ones that aren't checked.

<?php



while($row = mysql_fetch_assoc($query)){
    $id = $row["id"];
        $email = $row["user_email"];
    $androidId = $row["user_androidid"];
    $amount = $row["amount"];

    echo "<tr>
    <td><input id='data_id' name='data_id[]' size='25'  value='".$id."'/></td>
    <td><input id='mail' name='mail[]'size='25' value='".$email."'/></td>
    <td><input id='androidId' name='androidId[]' size='25' value='".$androidId."'/></td>
    <td><input id='amount' name='amount[]' size='25' value='".$amount."'/></td>
    <td>coming soon...</td>
    <td><input id='currency' name='currencyCode[]' size='25' value='USD'/></td>
    <td><input type='checkbox' name='chosen[]' value='".$id."'<td>
    </tr>";



}
?>

And I'm testing it like this:

for($i=0; $i<count($_POST["chosen"]); $i++){

echo $_POST["chosen"][$i];

}
for($i=0; $i<count($_POST["mail"]); $i++){

echo $_POST["mail"][$i];

}

For a specific example right now I have three rows, I "check" the first and the last.

When I parse the form data the checkbox array returns the values for the first and the last only, but if I try to parse the mail[] it has all the values for rows 1, 2, and 3.

Any ideas on how to properly configure this? I'm sure there's something wrong with the structure, just looking for confirmation.

解决方案

Try linking the input arrays together by giving them the same key, in this case $id -

while($row = mysql_fetch_assoc($query)){
    $id = $row["id"];
        $email = $row["user_email"];
    $androidId = $row["user_androidid"];
    $amount = $row["amount"];

    echo "<tr>
    <td><input id='data_id' name='data_id[".$id."]' size='25'  value='".$id."'/></td>
    <td><input id='mail' name='mail[".$id."]'size='25' value='".$email."'/></td>
    <td><input id='androidId' name='androidId[".$id."]' size='25' value='".$androidId."'/></td>
    <td><input id='amount' name='amount[".$id."]' size='25' value='".$amount."'/></td>
    <td>coming soon...</td>
    <td><input id='currency' name='currencyCode[".$id."]' size='25' value='USD'/></td>
    <td><input type='checkbox' name='chosen[".$id."]' value='".$id."'/><td>
    </tr>"; 
}

Then on the post you can get only the arrays that were checked -

foreach($_POST["chosen"] as $key=>$value){
     echo $_POST["data_id"][$key];
     echo $_POST["mail"][$key];
     echo $_POST["androidId"][$key];
     echo $_POST["amount"][$key];
     echo $_POST["currencyCode"][$key];
     echo $_POST["chosen"][$key];
}

这篇关于复选框只发送特定的行到php表单解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆