lcy Posted August 30, 2009 Share Posted August 30, 2009 Hi! Having some problems regarding radio buttons..hope to get some help here. Thanks in advance. Here's the code: $query = "SELECT * from replacement_leave WHERE a=1 && b=2 && c=3'"; $result = mysql_query($query) or die ("couldn't execute query"); <tr> while($row=mysql_fetch_array) { ?> <td><input name="replacement" type="radio" value="<?php echo $row['date']; echo $row['title']; ?>" checked></td> <td><?php echo $row['title']; ?></td> <td><?php echo date('d-m-Y',strtotime($row['date']));?></td> <td><?php echo $row['entitlement']; ?></td> <td><?php echo $left; ?></td> <td><?php echo $row['validity']; ?></td> </tr><? } ?> First, i need the radio button to be checked initially for the first value of the radio button. However, what i get is, the button is checked at the last item appears in the list of radio button. Second, after users make their choice and submit the form, they are able to return to this page. When they return to this page, the radio button is needed to be checked on the users' previously chosen button. But i don't know how to make this. Thanks again for helping. Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted August 30, 2009 Share Posted August 30, 2009 first use php or code tags. Makes it much easier to read. and try something along these lines. $a=0; while($row=mysql_fetch_array) { $checked=($a==0 || (isset($_POST['replacement']) && $_POST['replacement']==$row['date']))?"checked":""; ?> <td><input name="replacement" type="radio" value="<?php echo $row['date']; echo $row['title']; ?>" <?php echo $checked; ?>></td> <td><?php echo $row['title']; ?></td> <td><?php echo date('d-m-Y',strtotime($row['date']));?></td> <td><?php echo $row['entitlement']; ?></td> <td><?php echo $left; ?></td> <td><?php echo $row['validity']; ?></td> </tr><? } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.