I have a PHP form where fields are defined as item[fieldname][], where the set of fields are repeated via Jquery Clone function.
These rows post as following when submitted
[item] => Array ( [itemdate] => Array ( [0] => 2012-07-10 20:44:05 [1] => 2012-07-12 20:44:17 )
[flditmname] => Array ( [0] => sdc [1] => sd )
[fieldtype] => Array ( [0] => 1 [1] => 2 )
[subscribe] => Array ( [0] => X [1] => X )
)
Now I need to insert an element item[id][] in each of the rows that is submitted (something like a transaction number). I'm confused as to how to accomplish this. I thought of two ways :
Find the number of rows and then add the value by iteration. But for this I face a problem that the PHP count function does not return the correct value (it is counting every array as one and not the rows). I can count from the first element but I will not know it as my fields are populated dynamically.
Some kind of array push which can iterate through the rows and add my element with values.
Looking for help from experts here as to how I shall accomplish this. Or is there any other way that you can suggest how I can handle a header-item transaction posting where each item takes the reference of the header transaction id with a line item number (all fields dynamically populated)? The structure roughly will be as below :
Header: doc id | field1 | field2 | ...
Item: doc id | line no | field3 | field4 | ...
Doc id will be fetched from database as lastno+1 during posting.