Re: [PHP] Processing a table of input fields

2007-05-12 Thread Richard Lynch
Use name="attend[]"

This will simplify life immensely on the processing side where you can
just iterate through $_POST['attend'] as an array and have the
$user_id.

Ditto for the pay[] and other fields.

Note that the checkboxes will ONLY send in keys/values for the checked
ones -- You get nothing for the unchecked ones -- which is fine, you
assume they weren't there if they weren't checked.

On Fri, May 11, 2007 1:22 pm, Todd Cary wrote:
> I create a table of input fields so the user (secretary at a
> Rotary meeting) can check mark if the person attended and how
> much they paid for lunch.  Each input field name has the user ID
> as part of it.  What is the best way to process the table when
> the submit button is pressed?  There are about 50 rows in the table.
>
> Sample of one row for member 590:
>
> 
> 
> 
> 05/11/2007TheressaBryant type="text" name="590_pay" value="16" size="5" maxlength="4">
>  maxlength="4">
>  maxlength="25">
> 
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Processing a table of input fields

2007-05-11 Thread Todd Cary

Jim Lucas wrote:

Richard Davey wrote:

Todd Cary wrote:

I create a table of input fields so the user (secretary at a Rotary 
meeting) can check mark if the person attended and how much they paid 
for lunch.  Each input field name has the user ID as part of it.  
What is the best way to process the table when the submit button is 
pressed?  There are about 50 rows in the table.


Sample of one row for member 590:




05/11/2007TheressaBryanttype="text" name="590_pay" value="16" size="5" maxlength="4">
maxlength="4">





Personally I'd do it like this (if you are displaying say 50 
checkboxes on the page at once)


Name each checkbox so the they go into an array, i.e.:





Then in your PHP script you can simply loop through the attend array 
($_POST['attend']) and extract all the IDs of those people who were 
ticked. If they weren't ticked, they won't be in your array.


Cheers,

Rich

I would do it even a different way



05/11/2007
Theressa
Bryant
maxlength="4">
maxlength="4">
maxlength="25">




Then on the PHP side this.

if ( isset($_POST['list']) && count($_POST['list']) > 0 ) {
foreach ( $_POST['list'] AS $id => $data ) {
if ( isset($data['attend']) && $data['attend'] == '1' ) {
# do stuff related to them attending the meal
}
}
}


This way, everything the grouped in one big array.  You don't have to 
worry about checking for values in each array, it is all right there.  
Keeping things in sync is much easier this way.


Hope this helps



Thanks again!  Have it working for the initial entry and the 
recreation of the table for editing based on the array.


Todd

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Processing a table of input fields

2007-05-11 Thread Todd Cary

Jim Lucas wrote:

Richard Davey wrote:

Todd Cary wrote:

I create a table of input fields so the user (secretary at a Rotary 
meeting) can check mark if the person attended and how much they paid 
for lunch.  Each input field name has the user ID as part of it.  
What is the best way to process the table when the submit button is 
pressed?  There are about 50 rows in the table.


Sample of one row for member 590:




05/11/2007TheressaBryanttype="text" name="590_pay" value="16" size="5" maxlength="4">
maxlength="4">





Personally I'd do it like this (if you are displaying say 50 
checkboxes on the page at once)


Name each checkbox so the they go into an array, i.e.:





Then in your PHP script you can simply loop through the attend array 
($_POST['attend']) and extract all the IDs of those people who were 
ticked. If they weren't ticked, they won't be in your array.


Cheers,

Rich

I would do it even a different way



05/11/2007
Theressa
Bryant
maxlength="4">
maxlength="4">
maxlength="25">




Then on the PHP side this.

if ( isset($_POST['list']) && count($_POST['list']) > 0 ) {
foreach ( $_POST['list'] AS $id => $data ) {
if ( isset($data['attend']) && $data['attend'] == '1' ) {
# do stuff related to them attending the meal
}
}
}


This way, everything the grouped in one big array.  You don't have to 
worry about checking for values in each array, it is all right there.  
Keeping things in sync is much easier this way.


Hope this helps



WOW!  Now it is quite refined!  Thank you for contributions.

Todd

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Processing a table of input fields

2007-05-11 Thread Jim Lucas

Richard Davey wrote:

Todd Cary wrote:

I create a table of input fields so the user (secretary at a Rotary 
meeting) can check mark if the person attended and how much they paid 
for lunch.  Each input field name has the user ID as part of it.  What 
is the best way to process the table when the submit button is 
pressed?  There are about 50 rows in the table.


Sample of one row for member 590:




05/11/2007TheressaBryanttype="text" name="590_pay" value="16" size="5" maxlength="4">
maxlength="4">





Personally I'd do it like this (if you are displaying say 50 checkboxes 
on the page at once)


Name each checkbox so the they go into an array, i.e.:





Then in your PHP script you can simply loop through the attend array 
($_POST['attend']) and extract all the IDs of those people who were 
ticked. If they weren't ticked, they won't be in your array.


Cheers,

Rich

I would do it even a different way



05/11/2007
Theressa
Bryant






Then on the PHP side this.

if ( isset($_POST['list']) && count($_POST['list']) > 0 ) {
foreach ( $_POST['list'] AS $id => $data ) {
if ( isset($data['attend']) && $data['attend'] == '1' ) {
# do stuff related to them attending the meal
}
}
}


This way, everything the grouped in one big array.  You don't have to worry about checking for 
values in each array, it is all right there.  Keeping things in sync is much easier this way.


Hope this helps

--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Unknown

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Processing a table of input fields

2007-05-11 Thread Richard Davey

Todd Cary wrote:

I create a table of input fields so the user (secretary at a Rotary 
meeting) can check mark if the person attended and how much they paid 
for lunch.  Each input field name has the user ID as part of it.  What 
is the best way to process the table when the submit button is pressed?  
There are about 50 rows in the table.


Sample of one row for member 590:




05/11/2007TheressaBryanttype="text" name="590_pay" value="16" size="5" maxlength="4">
maxlength="4">





Personally I'd do it like this (if you are displaying say 50 checkboxes 
on the page at once)


Name each checkbox so the they go into an array, i.e.:





Then in your PHP script you can simply loop through the attend array 
($_POST['attend']) and extract all the IDs of those people who were 
ticked. If they weren't ticked, they won't be in your array.


Cheers,

Rich
--
Zend Certified Engineer
http://www.corephp.co.uk

"Never trust a computer you can't throw out of a window"

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Processing a table of input fields

2007-05-11 Thread Todd Cary
I create a table of input fields so the user (secretary at a 
Rotary meeting) can check mark if the person attended and how 
much they paid for lunch.  Each input field name has the user ID 
as part of it.  What is the best way to process the table when 
the submit button is pressed?  There are about 50 rows in the table.


Sample of one row for member 590:




05/11/2007TheressaBryanttype="text" name="590_pay" value="16" size="5" maxlength="4">
maxlength="4">
maxlength="25">



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php