Jump to content

Recommended Posts

Hi,

 

Anyone know the solution to this problem...?

 

I have a row of radio buttons for a single variable, and I want to connect the radio button selection with the variable, then pass it through a form.

 

I'm assuming I need to use an array, but I'm not exactly sure how to do that.

 

Here's a snippet of my code:

 

 

		while($question = mysql_fetch_array($questions)){
		echo '
			<div id="row">
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
			<td width="50%">' .$question['text']. '</td>
			<td width="10%"><div align="center">
			<input name="' .$question['id']. '" type="radio" value="1" />
			</div></td>
			<td width="10%"><div align="center">
			<input name="' .$question['id']. '" type="radio" value="2" />
			</div></td>
			<td width="10%"><div align="center">
			<input name="' .$question['id']. '" type="radio" value="3" />
			</div></td>
			<td width="10%"><div align="center">
			<input name="' .$question['id']. '" type="radio" value="4" />
			</div></td>
			<td width="10%"><div align="center">
			<input name="' .$question['id']. '" type="radio" value="5" />
			</div></td>
			</tr>
			</table>
			</div>
		';
	}

Link to comment
https://forums.phpfreaks.com/topic/266600-help/
Share on other sites

Radio buttons are supposed to represent just one thing - like, say gender, where even though there two options (M/F), there's only one possible choice that can be selected.  Having an array for radio buttons doesn't make much sense.

 

Check boxes, on the other hand, require arrays because multiple boxes can be checked.  In order to do that, simply make their names reference a PHP array:

 

<input type="checkbox" name="someArrayName[]" value="someValue" />

 

Note how the name has array notation (the []s), but is not a PHP variable (no $) and does not have any index (anything within the []s).

Link to comment
https://forums.phpfreaks.com/topic/266600-help/#findComment-1366310
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.