Page 1 of 1

Processing unknown amount of fields

Posted: Wed May 11, 2005 3:49 pm
by toni
Hello,

I am working on a project that will allow users to customize which questions they want to include on a survey.
The questions are stored in the database and are retrieved into a form like this:

Code: Select all

while ($Row = mysql_fetch_array($questionResult)) {
	print("<tr height=\"25\" align=\"left\">\n");
	print("<td align=\"left\"><input type='checkbox' checked value='$Row[ID]' name='questionChoice' /></td>\n");
	print("</tr>\n");
	}
My difficulty is trying to figure out how to process the fields since it will be an unknown amount of fields, plus unknown names. I saw a response to a question similar to this that mentioned changing the checkbox name to 'questionChoice[]' in order to make an array that could be processed. Could someone confirm that this would work? Or if someone has another idea that would work, I would appreciate hearing your comments/suggestions.

Thank you for your consideration.

Posted: Thu May 12, 2005 3:38 am
by phpScott
yes, by using something like <input type="checkbox" name="questions[]" value="uniqueValue" />

on the server side you will get an array called $questions with their values.

Posted: Thu May 12, 2005 3:39 pm
by toni
Thank you for your assistance!

Posted: Fri May 13, 2005 8:50 am
by patrikG
That's £12.50 you owe PhpScott for that answer.












































;)

Posted: Fri May 13, 2005 10:21 am
by phpScott
That will pay a round of drinks.








yeah :D