Re: determine number of entries Options (2)



On Jan 31, 8:20 am, question....@xxxxxxxxxxx wrote:
This is a followup to a previous question.

I have a form with a series of sequentially named input controls

<input type='text' name='IngQty1'
onChange='javascript:saveValue(1,this.value)'>
<input type='text' name='IngQty2'
onChange='javascript:saveValue(2,this.value)'>
<input type='text' name='IngQty3'
onChange='javascript:saveValue(3,this.value)'>
...

I am trying to count the number of instances of inputs IngQty# and
also loop through the values.

In a response (seehttp://groups.google.com/group/php.general/browse_thread/thread/fee55...)
I got previously I was given the following

foreach($_SERVER['POST']['foo'] as $key => $value) {
//do something with each one

}

count($_SERVER['POST']['IngQty'])

but it doesn't work (I should rephrase that and say I can't get it to
work).

The for each generates a "Warning: Invalid argument supplied for
foreach()" and the count always returns a value of 0.

Could someone help me get these functional.

Thank you for the help!

QB

If what you've got above is what you're using I wouldn't expect it to
work. You still have your form elements named IngQty1, IngQty2, etc.
You need to use IngQty[1], IngQty[2], etc. Then, your foreach should
look something like this:

foreach($_SERVER['POST']['IngQty'] as $key => $value)

Of course, if your form is using GET it needs to be $_SERVER['GET']
['IngQty'].
.