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"
}
}
php
New contributor
|
show 1 more comment
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"
}
}
php
New contributor
“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
|
show 1 more comment
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"
}
}
php
New contributor
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
php
New contributor
New contributor
New contributor
asked Nov 19 at 13:20
Mahmut
41
41
New contributor
New contributor
“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
|
show 1 more comment
“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
|
show 1 more comment
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!
add a comment |
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!
add a comment |
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!
add a comment |
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!
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!
answered Nov 19 at 15:16
Trent Reimer
16
16
add a comment |
add a comment |
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.
Mahmut is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
“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