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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.