468,248 Members | 1,533 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,248 developers. It's quick & easy.

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??

Apr 9 '07 #1
3 3476
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.
js*******@attglobal.net
==================
Apr 9 '07 #2
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">';
}

Apr 9 '07 #3
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='checked="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='checked="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.
Apr 9 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Michael Albanese | last post: by
1 post views Thread by Rage Matrix | last post: by
2 posts views Thread by forbes | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.