Hello Guys,

I am trying to update multiple table rows using dynamically generated radio buttons.

The radio buttons are in groups of two (yes and no) which also have dynamic names.

In other to give the group unique names, I have added row numbers to the group names as thus:

... some select statement...

while($row = mysql_fetch_array($result)){
echo "<input type=\"radio\" name=\"test".$rowId."\" value=\"yes\" />Yes 
<input type=\"radio\" name=\"test".$rowId."\" value=\"no\" checked=\"checked\" />No";

this works fine in grouping the buttons, but my problem is how to retrieve the value of the buttons when the form is submitted seeing that the group names are part dynamic.

Summarised in one sentence, I am trying to retrieve values of dynamically named radio button groups.

I am losing it. Somebody pls help.

7 Years
Discussion Span
Last Post by diafol

If test1 is a name:

$test1 = $_POST['test1']; //will give 'yes' or 'no'

If you don't know the 'key' for the 'test' it's going to be difficult. Perhaps placing an actual key would be possible:

... name = "test['$rowId']" ...

as an attribute.

Then in your form handling:

$arr = $_POST['test'];

$sqlkeyvalue = "";

foreach($arr as $key=>$value){
  if($value == 'yes'){
    $sqlval = 1;
    $sqlval = 0;
  $sqlkeyvalue .= ",`field{$key}` = $sqlvalue";

$sql = mysql_query("INSERT INTO table1 SET " . substr($sqlkeyvalue,0,-1) WHERE ...");

I haven't tried this so I can't say if it's even possible, but I think it's pretty close.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.