Get values from table column if row checked











up vote
0
down vote

favorite












I am using PHP to get values from the table and need to process them further.
If row is checked I need to get values from columns Quantity and FMK Code.



Table:



<table class="table table-bordered">
<thead>
<tr class="success">
<th>#<br/></th>
<th>Article </th>
<th>Name </th>
<th>Quantity</th>
<th>FMK CODE<br/></th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
while($r=$q->fetch()){ ?>
<tr>
<td><input type="checkbox" class="from-control" name="id" value="<?php echo $r['id']?>"></td>
<td><?=$r['Article']?></td>
<td><?=$r['Name']?></td>
<td><input type="text" class="form-control" value="<?=$r['quantity'];?>" name="quantity"></td>
<td>
<select class="form-control col-lg-2" name="childCode"><?php getChildCodes($r["code"]) ?></select>
</td>
</tr>
<?php } ?>
</tbody>
</table>


On submit I need to get values from "quantity and childCode" for each row selected.



<button type="submit" name="getValues"> Submit </button>


PhP processing:



<?php 

if (isset($_POST['getValues'])) {

$id = $_POST['id'];
$quantity = $_POST['quantity'];
$childCode = $_POST['childCode'];

$values = array();

foreach($id as $id) {
foreach($quantity as $quant){
foreach($childCode as $code){
array_push($values, $id,$quant,$code);
}
}
echo "<pre>";
var_dump($values);
echo "</pre>";
}
?>


values output. In output I get all values from table, no matter if they are checked or not which is wrong. Also array print was not well, values from one name form array. I need array to be formed first element of id, quantity, child code to b one array. [0]=>"177239","10.000",113



array(3) {
[0]=>
array(1) {
[0]=>
array(3) {
[0]=>
string(6) "177239"
[1]=>
string(6) "177240"
[2]=>
string(6) "177241"
}
}
[1]=>
array(3) {
[0]=>
string(6) "10.000"
[1]=>
string(7) "100.000"
[2]=>
string(6) "10.000"
}
[2]=>
array(3) {
[0]=>
string(11) "113"
[1]=>
string(10) "87"
[2]=>
string(10) "91"
}
}









share|improve this question







New contributor




Mahmut is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • “In output I get all values from table, no matter if they are checked or not which is wrong.” - normal text input fields will always submit a value, so this is not “wrong”. (It might not be what you want, but that and “wrong” are two different things.) “I need array to be formed first element of id, quantity, child code to b one array. [0]=>"177239","10.000",113” - then you need to name your form fields accordingly to begin with. foo[0][0] for the checkbox, foo[0][1] for the text field, foo[0][2] for the select, and so on for the following rows, foo[1][0], foo[1][1], etc.
    – misorude
    Nov 19 at 13:25










  • @ Thanks, but I don't understand quite well
    – Mahmut
    Nov 19 at 13:32










  • What are you having problems with? Did you try it with field names like I suggested, and then checked what result you get? (var_dump or print_r of $_POST, so that you can see what the structure is like.)
    – misorude
    Nov 19 at 13:34










  • @misorude Could you write example of naming
    – Mahmut
    Nov 20 at 9:33










  • I already gave you an example, and Trent’s answer provides a different way. Again: Try something with those suggestions, and use var_dump to see what structure you get with that in $_POST.
    – misorude
    Nov 20 at 9:42















up vote
0
down vote

favorite












I am using PHP to get values from the table and need to process them further.
If row is checked I need to get values from columns Quantity and FMK Code.



Table:



<table class="table table-bordered">
<thead>
<tr class="success">
<th>#<br/></th>
<th>Article </th>
<th>Name </th>
<th>Quantity</th>
<th>FMK CODE<br/></th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
while($r=$q->fetch()){ ?>
<tr>
<td><input type="checkbox" class="from-control" name="id" value="<?php echo $r['id']?>"></td>
<td><?=$r['Article']?></td>
<td><?=$r['Name']?></td>
<td><input type="text" class="form-control" value="<?=$r['quantity'];?>" name="quantity"></td>
<td>
<select class="form-control col-lg-2" name="childCode"><?php getChildCodes($r["code"]) ?></select>
</td>
</tr>
<?php } ?>
</tbody>
</table>


On submit I need to get values from "quantity and childCode" for each row selected.



<button type="submit" name="getValues"> Submit </button>


PhP processing:



<?php 

if (isset($_POST['getValues'])) {

$id = $_POST['id'];
$quantity = $_POST['quantity'];
$childCode = $_POST['childCode'];

$values = array();

foreach($id as $id) {
foreach($quantity as $quant){
foreach($childCode as $code){
array_push($values, $id,$quant,$code);
}
}
echo "<pre>";
var_dump($values);
echo "</pre>";
}
?>


values output. In output I get all values from table, no matter if they are checked or not which is wrong. Also array print was not well, values from one name form array. I need array to be formed first element of id, quantity, child code to b one array. [0]=>"177239","10.000",113



array(3) {
[0]=>
array(1) {
[0]=>
array(3) {
[0]=>
string(6) "177239"
[1]=>
string(6) "177240"
[2]=>
string(6) "177241"
}
}
[1]=>
array(3) {
[0]=>
string(6) "10.000"
[1]=>
string(7) "100.000"
[2]=>
string(6) "10.000"
}
[2]=>
array(3) {
[0]=>
string(11) "113"
[1]=>
string(10) "87"
[2]=>
string(10) "91"
}
}









share|improve this question







New contributor




Mahmut is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • “In output I get all values from table, no matter if they are checked or not which is wrong.” - normal text input fields will always submit a value, so this is not “wrong”. (It might not be what you want, but that and “wrong” are two different things.) “I need array to be formed first element of id, quantity, child code to b one array. [0]=>"177239","10.000",113” - then you need to name your form fields accordingly to begin with. foo[0][0] for the checkbox, foo[0][1] for the text field, foo[0][2] for the select, and so on for the following rows, foo[1][0], foo[1][1], etc.
    – misorude
    Nov 19 at 13:25










  • @ Thanks, but I don't understand quite well
    – Mahmut
    Nov 19 at 13:32










  • What are you having problems with? Did you try it with field names like I suggested, and then checked what result you get? (var_dump or print_r of $_POST, so that you can see what the structure is like.)
    – misorude
    Nov 19 at 13:34










  • @misorude Could you write example of naming
    – Mahmut
    Nov 20 at 9:33










  • I already gave you an example, and Trent’s answer provides a different way. Again: Try something with those suggestions, and use var_dump to see what structure you get with that in $_POST.
    – misorude
    Nov 20 at 9:42













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am using PHP to get values from the table and need to process them further.
If row is checked I need to get values from columns Quantity and FMK Code.



Table:



<table class="table table-bordered">
<thead>
<tr class="success">
<th>#<br/></th>
<th>Article </th>
<th>Name </th>
<th>Quantity</th>
<th>FMK CODE<br/></th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
while($r=$q->fetch()){ ?>
<tr>
<td><input type="checkbox" class="from-control" name="id" value="<?php echo $r['id']?>"></td>
<td><?=$r['Article']?></td>
<td><?=$r['Name']?></td>
<td><input type="text" class="form-control" value="<?=$r['quantity'];?>" name="quantity"></td>
<td>
<select class="form-control col-lg-2" name="childCode"><?php getChildCodes($r["code"]) ?></select>
</td>
</tr>
<?php } ?>
</tbody>
</table>


On submit I need to get values from "quantity and childCode" for each row selected.



<button type="submit" name="getValues"> Submit </button>


PhP processing:



<?php 

if (isset($_POST['getValues'])) {

$id = $_POST['id'];
$quantity = $_POST['quantity'];
$childCode = $_POST['childCode'];

$values = array();

foreach($id as $id) {
foreach($quantity as $quant){
foreach($childCode as $code){
array_push($values, $id,$quant,$code);
}
}
echo "<pre>";
var_dump($values);
echo "</pre>";
}
?>


values output. In output I get all values from table, no matter if they are checked or not which is wrong. Also array print was not well, values from one name form array. I need array to be formed first element of id, quantity, child code to b one array. [0]=>"177239","10.000",113



array(3) {
[0]=>
array(1) {
[0]=>
array(3) {
[0]=>
string(6) "177239"
[1]=>
string(6) "177240"
[2]=>
string(6) "177241"
}
}
[1]=>
array(3) {
[0]=>
string(6) "10.000"
[1]=>
string(7) "100.000"
[2]=>
string(6) "10.000"
}
[2]=>
array(3) {
[0]=>
string(11) "113"
[1]=>
string(10) "87"
[2]=>
string(10) "91"
}
}









share|improve this question







New contributor




Mahmut is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I am using PHP to get values from the table and need to process them further.
If row is checked I need to get values from columns Quantity and FMK Code.



Table:



<table class="table table-bordered">
<thead>
<tr class="success">
<th>#<br/></th>
<th>Article </th>
<th>Name </th>
<th>Quantity</th>
<th>FMK CODE<br/></th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
while($r=$q->fetch()){ ?>
<tr>
<td><input type="checkbox" class="from-control" name="id" value="<?php echo $r['id']?>"></td>
<td><?=$r['Article']?></td>
<td><?=$r['Name']?></td>
<td><input type="text" class="form-control" value="<?=$r['quantity'];?>" name="quantity"></td>
<td>
<select class="form-control col-lg-2" name="childCode"><?php getChildCodes($r["code"]) ?></select>
</td>
</tr>
<?php } ?>
</tbody>
</table>


On submit I need to get values from "quantity and childCode" for each row selected.



<button type="submit" name="getValues"> Submit </button>


PhP processing:



<?php 

if (isset($_POST['getValues'])) {

$id = $_POST['id'];
$quantity = $_POST['quantity'];
$childCode = $_POST['childCode'];

$values = array();

foreach($id as $id) {
foreach($quantity as $quant){
foreach($childCode as $code){
array_push($values, $id,$quant,$code);
}
}
echo "<pre>";
var_dump($values);
echo "</pre>";
}
?>


values output. In output I get all values from table, no matter if they are checked or not which is wrong. Also array print was not well, values from one name form array. I need array to be formed first element of id, quantity, child code to b one array. [0]=>"177239","10.000",113



array(3) {
[0]=>
array(1) {
[0]=>
array(3) {
[0]=>
string(6) "177239"
[1]=>
string(6) "177240"
[2]=>
string(6) "177241"
}
}
[1]=>
array(3) {
[0]=>
string(6) "10.000"
[1]=>
string(7) "100.000"
[2]=>
string(6) "10.000"
}
[2]=>
array(3) {
[0]=>
string(11) "113"
[1]=>
string(10) "87"
[2]=>
string(10) "91"
}
}






php






share|improve this question







New contributor




Mahmut is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Mahmut is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Mahmut is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 19 at 13:20









Mahmut

41




41




New contributor




Mahmut is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Mahmut is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Mahmut is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • “In output I get all values from table, no matter if they are checked or not which is wrong.” - normal text input fields will always submit a value, so this is not “wrong”. (It might not be what you want, but that and “wrong” are two different things.) “I need array to be formed first element of id, quantity, child code to b one array. [0]=>"177239","10.000",113” - then you need to name your form fields accordingly to begin with. foo[0][0] for the checkbox, foo[0][1] for the text field, foo[0][2] for the select, and so on for the following rows, foo[1][0], foo[1][1], etc.
    – misorude
    Nov 19 at 13:25










  • @ Thanks, but I don't understand quite well
    – Mahmut
    Nov 19 at 13:32










  • What are you having problems with? Did you try it with field names like I suggested, and then checked what result you get? (var_dump or print_r of $_POST, so that you can see what the structure is like.)
    – misorude
    Nov 19 at 13:34










  • @misorude Could you write example of naming
    – Mahmut
    Nov 20 at 9:33










  • I already gave you an example, and Trent’s answer provides a different way. Again: Try something with those suggestions, and use var_dump to see what structure you get with that in $_POST.
    – misorude
    Nov 20 at 9:42


















  • “In output I get all values from table, no matter if they are checked or not which is wrong.” - normal text input fields will always submit a value, so this is not “wrong”. (It might not be what you want, but that and “wrong” are two different things.) “I need array to be formed first element of id, quantity, child code to b one array. [0]=>"177239","10.000",113” - then you need to name your form fields accordingly to begin with. foo[0][0] for the checkbox, foo[0][1] for the text field, foo[0][2] for the select, and so on for the following rows, foo[1][0], foo[1][1], etc.
    – misorude
    Nov 19 at 13:25










  • @ Thanks, but I don't understand quite well
    – Mahmut
    Nov 19 at 13:32










  • What are you having problems with? Did you try it with field names like I suggested, and then checked what result you get? (var_dump or print_r of $_POST, so that you can see what the structure is like.)
    – misorude
    Nov 19 at 13:34










  • @misorude Could you write example of naming
    – Mahmut
    Nov 20 at 9:33










  • I already gave you an example, and Trent’s answer provides a different way. Again: Try something with those suggestions, and use var_dump to see what structure you get with that in $_POST.
    – misorude
    Nov 20 at 9:42
















“In output I get all values from table, no matter if they are checked or not which is wrong.” - normal text input fields will always submit a value, so this is not “wrong”. (It might not be what you want, but that and “wrong” are two different things.) “I need array to be formed first element of id, quantity, child code to b one array. [0]=>"177239","10.000",113” - then you need to name your form fields accordingly to begin with. foo[0][0] for the checkbox, foo[0][1] for the text field, foo[0][2] for the select, and so on for the following rows, foo[1][0], foo[1][1], etc.
– misorude
Nov 19 at 13:25




“In output I get all values from table, no matter if they are checked or not which is wrong.” - normal text input fields will always submit a value, so this is not “wrong”. (It might not be what you want, but that and “wrong” are two different things.) “I need array to be formed first element of id, quantity, child code to b one array. [0]=>"177239","10.000",113” - then you need to name your form fields accordingly to begin with. foo[0][0] for the checkbox, foo[0][1] for the text field, foo[0][2] for the select, and so on for the following rows, foo[1][0], foo[1][1], etc.
– misorude
Nov 19 at 13:25












@ Thanks, but I don't understand quite well
– Mahmut
Nov 19 at 13:32




@ Thanks, but I don't understand quite well
– Mahmut
Nov 19 at 13:32












What are you having problems with? Did you try it with field names like I suggested, and then checked what result you get? (var_dump or print_r of $_POST, so that you can see what the structure is like.)
– misorude
Nov 19 at 13:34




What are you having problems with? Did you try it with field names like I suggested, and then checked what result you get? (var_dump or print_r of $_POST, so that you can see what the structure is like.)
– misorude
Nov 19 at 13:34












@misorude Could you write example of naming
– Mahmut
Nov 20 at 9:33




@misorude Could you write example of naming
– Mahmut
Nov 20 at 9:33












I already gave you an example, and Trent’s answer provides a different way. Again: Try something with those suggestions, and use var_dump to see what structure you get with that in $_POST.
– misorude
Nov 20 at 9:42




I already gave you an example, and Trent’s answer provides a different way. Again: Try something with those suggestions, and use var_dump to see what structure you get with that in $_POST.
– misorude
Nov 20 at 9:42












1 Answer
1






active

oldest

votes

















up vote
0
down vote













misorude is pointing out that you need to name the form elements in a style that builds a PHP array. That is done with the characters as mentioned. So the first row would have element names like <input name="id[0]" ..., <input name="quantity[0]" .... The second row would have element names like <input name="id[1]" and <input name="quantity[1]"



Also make sure the foreach block doesn't overwrite the $id variable :)



foreach($id as $id) // Oops!





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });






    Mahmut is a new contributor. Be nice, and check out our Code of Conduct.










     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375534%2fget-values-from-table-column-if-row-checked%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    misorude is pointing out that you need to name the form elements in a style that builds a PHP array. That is done with the characters as mentioned. So the first row would have element names like <input name="id[0]" ..., <input name="quantity[0]" .... The second row would have element names like <input name="id[1]" and <input name="quantity[1]"



    Also make sure the foreach block doesn't overwrite the $id variable :)



    foreach($id as $id) // Oops!





    share|improve this answer

























      up vote
      0
      down vote













      misorude is pointing out that you need to name the form elements in a style that builds a PHP array. That is done with the characters as mentioned. So the first row would have element names like <input name="id[0]" ..., <input name="quantity[0]" .... The second row would have element names like <input name="id[1]" and <input name="quantity[1]"



      Also make sure the foreach block doesn't overwrite the $id variable :)



      foreach($id as $id) // Oops!





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        misorude is pointing out that you need to name the form elements in a style that builds a PHP array. That is done with the characters as mentioned. So the first row would have element names like <input name="id[0]" ..., <input name="quantity[0]" .... The second row would have element names like <input name="id[1]" and <input name="quantity[1]"



        Also make sure the foreach block doesn't overwrite the $id variable :)



        foreach($id as $id) // Oops!





        share|improve this answer












        misorude is pointing out that you need to name the form elements in a style that builds a PHP array. That is done with the characters as mentioned. So the first row would have element names like <input name="id[0]" ..., <input name="quantity[0]" .... The second row would have element names like <input name="id[1]" and <input name="quantity[1]"



        Also make sure the foreach block doesn't overwrite the $id variable :)



        foreach($id as $id) // Oops!






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 at 15:16









        Trent Reimer

        16




        16






















            Mahmut is a new contributor. Be nice, and check out our Code of Conduct.










             

            draft saved


            draft discarded


















            Mahmut is a new contributor. Be nice, and check out our Code of Conduct.













            Mahmut is a new contributor. Be nice, and check out our Code of Conduct.












            Mahmut is a new contributor. Be nice, and check out our Code of Conduct.















             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375534%2fget-values-from-table-column-if-row-checked%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Wiesbaden

            Marschland

            Dieringhausen