Multiple Radio Button Groups - Please Help! :)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Abersparky

    #1

    Multiple Radio Button Groups - Please Help! :)

    I'm having a problem with multiple radio button groups within a while
    loop. I have the page made so it pulls from a database the row values
    - one of which is a Y or N value. I have a radio button group for the
    Y and N value for each row of the database that gets pulled but only
    the last row will populate the value retrieved from the db. I know
    that I have to create a unique name for the radio buttons for each row
    - but I don't know how to increment the value automatically for each
    row... help??

  • Jerry Stuckle

    #2
    Re: Multiple Radio Button Groups - Please Help! :)

    Abersparky wrote:
    I'm having a problem with multiple radio button groups within a while
    loop. I have the page made so it pulls from a database the row values
    - one of which is a Y or N value. I have a radio button group for the
    Y and N value for each row of the database that gets pulled but only
    the last row will populate the value retrieved from the db. I know
    that I have to create a unique name for the radio buttons for each row
    - but I don't know how to increment the value automatically for each
    row... help??
    >
    The best way to get help with your code is to post it.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Abersparky

      #3
      Re: Multiple Radio Button Groups - Please Help! :)

      How do I get the radio name to automatically increment?? (and by the
      way I know I totally butchered the name value that's there lol)

      if ($w_row['vis']=='Y') {
      print '<input name="{$w_row["comment_id "]}" type="radio" checked
      value="Y">';
      } else {
      print '<input name="{$w_row["comment_id "]}" type="radio" value="Y">';
      }

      if ($w_row['vis']=='N') {
      print '<input name="{$w_row["comment_id "]}" type="radio" checked
      value="N">';
      } else {
      print '<input name="{$w_row["comment_id "]}" type="radio" value="N">';
      }

      Comment

      • Tyno Gendo

        #4
        Re: Multiple Radio Button Groups - Please Help! :)

        Abersparky wrote:
        How do I get the radio name to automatically increment?? (and by the
        way I know I totally butchered the name value that's there lol)
        >
        if ($w_row['vis']=='Y') {
        print '<input name="{$w_row["comment_id "]}" type="radio" checked
        value="Y">';
        } else {
        print '<input name="{$w_row["comment_id "]}" type="radio" value="Y">';
        }
        >
        if ($w_row['vis']=='N') {
        print '<input name="{$w_row["comment_id "]}" type="radio" checked
        value="N">';
        } else {
        print '<input name="{$w_row["comment_id "]}" type="radio" value="N">';
        }
        >
        You are using single quotes on the print, that will mean that the names
        will literally be "{$w_row... }" I think by just glancing at it, but
        assuming your comment_id is an INT AUTO_NUMBER PRIMARY KEY then your
        code should be fine if you hadn't used single quotes. You don't need to
        write your whole INPUT twice, just set a value for 'checked' to be
        inserted into the input code, I'd do something like:

        $w_row['vis'] == 'Y' ? $checked='check ed="checked"' : $checked="";
        echo '<input name="comment' . $w_row["comment_id "] . '" type="radio"
        ' . $checked . ' />';

        Or if you don't like the 3step if (tertiary or whatever..) ...

        $checked = '';
        if ( $w_row['vis'] == 'Y' ) {
        $checked='check ed="checked"';
        }
        echo '<input name="comment' . $w_row["comment_id "] . '" type="radio"
        ' . $checked . ' />';


        hope that helps. you should end up with radio's called comment1,
        comment2, comment3 etc. depending on your comment_id field's primary key
        values.

        Comment

        Working...