Arrays in a Form Question

From: Date: Mon, 18 Sep 2000 16:18:32 +0000
Subject: Arrays in a Form Question
Groups: php.general 
Request: Send a blank email to php-general+get-17136@lists.php.net to get a copy of this message
I've spent the past few hours NOT figuring out how to get this to work, hopefully someone on the list can provide some guidance. I've got a form page that shows a user-defined set of input fields. So if the user says "3", the form provides 3 sets of input fields like below: <input type="text" name="abc" value="123" size="20" maxlength="50"> <input type="text" name="def" value="456" size="20" maxlength="50"> <input type="text" name="ghi" value="789" size="20" maxlength="50"> Originally I had the form fields sitting in a while loop that does the following: <set 1> <input type="text" name="abc_1" value="123" size="20" maxlength="50"> <input type="text" name="def_1" value="456" size="20" maxlength="50"> <input type="text" name="ghi_1" value="789" size="20" maxlength="50"> <set 2> <input type="text" name="abc_2" value="123" size="20" maxlength="50"> <input type="text" name="def_2" value="456" size="20" maxlength="50"> <input type="text" name="ghi_2" value="789" size="20" maxlength="50"> <set 3> <input type="text" name="abc_3" value="123" size="20" maxlength="50"> <input type="text" name="def_3" value="456" size="20" maxlength="50"> <input type="text" name="ghi_3" value="789" size="20" maxlength="50"> etc... This is kind of ugly and it seems inefficient so I'm trying to figure out how to do this with a 2D array (there are multiple fields per "record"). I've tried the following which does not work. <ex. $abc count = 1, one set> <input type="text" name="<? echo "$abcdefghi_array[$abc_count][1]"; ?>" value="<? echo "$abcdefghi_array[$count][1]"; ?>" size="20" maxlength="50"> <input type="text" name="<? echo "$abcdefghi_array[$abc_count][2]"; ?>" value="<? echo "$abcdefghi_array[$count][2]"; ?>" size="20" maxlength="50"> <input type="text" name="<? echo "$abcdefghi_array[$abc_count][3]"; ?>" value="<? echo "$abcdefghi_array[$count][3]"; ?>" size="20" maxlength="50"> The name parameter seems to get messed up and I'm not sure how to keep the name parameter unique without resorting to my previous method of concatenating some text at the end of the name string. Is there a way to do this? Any ideas, suggestions, etc. would be greatly appreciated. Thanks. -- Clarence -> clarencek@ifurnishing.com

« previous php.general (#17136) next »