Display checkbox in front of each row

Hello. I have this table that prints out data from the DB. I would like to generate a radio in front of each row that will be generated. How can I do this inside my table body? Thanks.

<table class="table table-striped">
          <thead>
            <tr>
              <th>ID</th>
              <th>Name</th>
              <th>Surname</th>
              
            </tr>
          </thead>
          <tbody>

            <?php 
            require_once ('database_initialisation.php');
            $table = "members"; 
            $array = $admin_query->viewTableData($table);
            foreach ($array as $row)
            {

            echo 
                "

                <tr>
                  <td>" . $row['member_id'] . "</td>
                  <td>" . $row['member_id'] . "</td>
                  <td>" . $row['member_first_name'] .  "</td>
                  <td>" . $row['member_last_name'] .  "</td>
                  </tr>";
            } ?>

          </tbody>
        </table>

Add a beginning <td>.

            echo 
                "
                <tr>
                  <td><input type=\"radio\" name=\"whatever\" value=\"Whatever\"></td>
                  <td>" . $row['member_id'] . "</td>
                  <td>" . $row['member_id'] . "</td>
                  <td>" . $row['member_first_name'] .  "</td>
                  <td>" . $row['member_last_name'] .  "</td>
                  </tr>";
            } 

@RyanReese Thanks :slight_smile: I tried this before posting, but I forget to escape the " " :slight_smile:

@RyanReese If I have radios generated for every row, how can I know for each row which radio is selected. For example if I select the radio for the third row, I want it to perform a function, like get that row ID. Thanks

You can simply make each rows radio look like this.

<td><input type=\"radio\" name=\"whatever[]\" value=\"Whatever\"></td>

Then in your PHP form processing find what value $_POST[‘whatever’] is and from there you can determine what row you need. I dunno; I’m no PHP guru. I assume there is a better way and I don’t want to give bad advice and screw you over.

@RyanReese Thanks anyway

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.