Processing unknown amount of fields

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
toni
Forum Newbie
Posts: 11
Joined: Fri Jan 09, 2004 8:30 pm

Processing unknown amount of fields

Post 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.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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.
toni
Forum Newbie
Posts: 11
Joined: Fri Jan 09, 2004 8:30 pm

Post by toni »

Thank you for your assistance!
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

That's £12.50 you owe PhpScott for that answer.












































;)
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

That will pay a round of drinks.








yeah :D
Post Reply