Reply to Re: How do I display radio button results?

Your name:

Reply:


Posted by Pedro Graca on 10/30/06 17:17

Bob Sanderson wrote:
> I have a form which uses several radio buttons to enter data. It works fine
> as far as entering goes, but I can't figure out how to display which button
> is checked when I view the record. I could do a if-then routine but it
> seems like there should be an easier way.
>
> Any help will be greatly appreciated.

What's your HTML like and how are you dealing with it in PHP?

This (with possible unintended errors corrected) works:

<!-- HTML, assume correct DOCTYPE, ... -->
<form ...>
<div class="group1">
<label><input type="radio" name="r[0]" value="0" checked>none</label>
<label><input type="radio" name="r[0]" value="1">one</label>
<label><input type="radio" name="r[0]" value="1">two</label>
</div>
<div class="group2">
<label><input type="radio" name="r[1]" value="0" checked>none</label>
<label><input type="radio" name="r[1]" value="1">one</label>
<label><input type="radio" name="r[1]" value="1">two</label>
</div>
<!-- some submit button -->
</form>

And the PHP that deals with it could be

<?php
foreach ($_POST['r'] as $k=>$radio) {
echo 'For group ', $k, ', you selected the option with ',
$radio, " for its value.<br>\n";
}
?>

--
I (almost) never check the dodgeit address.
If you *really* need to mail me, use the address in the Reply-To
header with a message in *plain* *text* *without* *attachments*.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация