Jump to content

HELP!


Channel6

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.