hey guys so i have a table where the <tbody> is populated by data in php. a row has 4 columns: name, unconfirmed, attending and unattending. the last 3 columns are radio buttons(echoed). the problem is that the radio buttons cannot be checked. for example for first row unconfirmed is clicked then second row attending is clicked then for the third row attending is clicked but then the second rows radio button is unclicked(like it moves from second row to third row). how do i go around this?

<table class="rsvp-guest-table">
        <thead>
            <tr>
                <th style="width:100px">Guests</th>
                <th>Unconfirmed</th>
                <th>Attending</th>
                <th>Unattending</th>
            </tr>
        </thead>
        <tbody>
                <?php
                        require "connection.php";

                        $check = mysql_query("SELECT salutation,fname,lname FROM contact") or die(mysql_error());
                        if(mysql_num_rows($check) > 0)
                        {
                            while($row = mysql_fetch_array($check))
                            {
                                $salutation = $row['salutation'];
                                $firstname = $row['fname'];
                                $lastname = $row['lname'];

                                echo 
                                "<tr>
                                    <td>$salutation $firstname $lastname</td><td><input type='radio' name='unconfirmed' class='radio' value='unconfirmed'></td><td><input type='radio' name='attending' class='rad' value='attend'></td><td><input type='radio' name='unattending' class='radi' value='notattend'></td>
                                </tr>";
                            }
                        }   
                        else
                            {
                                echo 
                                "<tr>
                                    <td colspan='4'>Choose an Event from the list.</td>
                                </tr>";
                            }
                    ?>
            </tbody>
    </table>

2f6c3b31a6bb924b822fdecb88c646bf

hi nadiam ,
first you have to know one thing about radio buttons functionality
if you want select one radio button among three or group of radio buttons then you should go like as follows (name of radio buttons are same)

<input type="radio" name="status" value="unconfirmed"> unconfirmed
<input type="radio" name="status" value="attended"> attended
<input type="radio" name="status" value="not attended"> not attended

from the above group you can select only one

similary what i am understanding from the given picture & the code is
for example your giving the same names(suppose unconfirmed column) to all the radio buttons of unconfirmed column in all rows so you could select only one from the entire unconfirmed column not on each record

try to change your code to give different names to each row column group

what i mean is try to give as follows for each row

<input type="radio" name="status[some_dunamic value_for_this_row]" value="unconfirmed"> unconfirmed
<input type="radio" name="status[some_dunamic value_for_this_row]" value="attended"> attended
<input type="radio" name="status[some_dunamic value_for_this_row]" value="not attended"> not attended

so that you can achieve your functionality successfully.

pls try do as above said

let me know if you any doubts in my clariification

note : sorry for my poor written skills

note: comments are appreciated

Thanks radha! I actually figured the names thing a few minutes ago. I keep forgetting that the names have to be the same for checkboxes and radiobuttons which always gives me hell coz of that fact. Haha. Anyways, thanks for the response! I will look at it again and try what u suggested when I have my laptop near me. And if I have any questions I will post here.

Member Avatar for diafol

As pointed out, your radiobuttons in a single row must have the same name. You originally had the same name for all radiobuttons regardless of row.

The 'some_dynamic_value' ideally would be the 'id' value of some field e.g. user_id. However, it's difficult to see what this form is trying to achieve.

If it's for an admin, fine - the admin can change the data and update. Although, it would be far easier for each user to update their own record, as opposed to aan admin having to make changes. If it's for the general user - there shouldn't be active radiobuttons AFAICS. If general users are not allowed to change everybody else's statuses, they shouldn't be misled with readiobuttons. Radiobuttons do not serve 'show' purpose in this context. A tick or circle (e.g. &bull;) in a column may be more appropriate.

//EDIT

Looking at it again - ignore my comments, I see now that this is an admin-type control form. Heh - getting old :)

someone suggested this to me.

<?php
require "connection.php";

// Processing
if(isset($_POST['submit'])){
    foreach($_POST['rsvp'] as $id => $value):
        $id    = mysql_real_escape_string($id);
        $value = mysql_real_escape_string($value);
        $sql = "UPDATE guest SET status = '$value' WHERE guest_id = '$id'";
        mysql_query($sql);
    endforeach;
}
$display = "";
$check = mysql_query ("SELECT * FROM guest");
if (mysql_num_rows($check) > 0)
{
    while ($row = mysql_fetch_array ($check))
    {
        $id = $row['guest_id'];
        $name = $row ['guest_name'];
        $status = $row ['status'];

        $status_array = array("unconfirmed", "attending", "not attending");
        $display .="<tr>
        <td>$salutation $name</td>";
        foreach($status_array as $k => $v):

            $checked = ($status == $k ? ' checked="checked"' : '');     
            $display .="<td><input type='radio' name='rsvp[" . $id . "]' value='" . $k . "'" . $checked . " />" . $v . "</td>"; 

        endforeach;
        $display .="</tr>";
    }
}   
?>
<table class="rsvp-guest-table">
            <thead>
                <th style="width:100px;text-align:center">Guests</th>
                <th colspan="3" style="text-align:center">Status</th>
            </thead>
            <tbody>
                <?php
                    echo $display;
                ?>
            </tbody>
        </table>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.