View Single Post
  #2 (permalink)  
Old Aug 20th, 2005, 20:38
grahame grahame is offline
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
How's this?

Code: Select all
<?php
if ($_REQUEST[completed]) {
    $report = "";
    for ($k=1; $k<6; $k++) {
        if ($_REQUEST["service".$k]) {
            $report .= $report ? ", " : "Service: ";
            $report .= "service".$k;
        }
    }
} else {
    $report = "Your results will appear here";
}
?>
<html>
<head><title>Demo to answer Forum question</title></head>
<body>
<h1>Select from a series of radio boxes</h1>
<?= $report ?><hr>
<form><input type=hidden name=completed value=1>
<input name=service1 type=radio> 05:52 to Swindon

<input name=service2 type=radio> 07:45 to Swindon

<input name=service3 type=radio> 13:35 to Swindon

<input name=service4 type=radio> 17:02 to Swindon

<input name=service5 type=radio> 21:33 to Swindon

<input type=submit></form>
<hr>
By Graham Ellis, graham@wellho.net
</body>
</html>
Complete running code

Note - I dislike repeated code in my PHP (such as checking a series of variables with a pattern of names) as it makes the code hard to extend if more repetitions are added later, so I've provided a slightly complex loop that could easily be expanded if the service increased from 5 to 50 a day!
Reply With Quote