Jump to content

need some help with radio button


lcy

Recommended Posts

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. ;)

Link to comment
https://forums.phpfreaks.com/topic/172455-need-some-help-with-radio-button/
Share on other sites

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.