Channel6 Posted August 2, 2012 Share Posted August 2, 2012 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> '; } Quote Link to comment Share on other sites More sharing options...
Berre Posted August 2, 2012 Share Posted August 2, 2012 Do you think "HELP!" is a good subject? 100% of the topics here could have that subject. Anyway, I don't understand your problem or what you want to achieve. Your code example doesn't seem to have any problems. Quote Link to comment Share on other sites More sharing options...
Channel6 Posted August 2, 2012 Author Share Posted August 2, 2012 Hahah. Maybe I should rephrase it then: Basically, I want to get an array() from a $_POST[]. Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 2, 2012 Share Posted August 2, 2012 A radio can only have one option selected, so it will never be an array. If you have a multi-select or a set of checkboxes, the name would be name="fieldname[]" and it would show up as $_POST['fieldname'] on the processing page. Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted August 2, 2012 Share Posted August 2, 2012 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). Quote Link to comment Share on other sites More sharing options...
Mahngiel Posted August 2, 2012 Share Posted August 2, 2012 $_POST is already an array and any inputs will be represented as a key, pair (name, value) within that superglobal upon a POST method. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.