Hello. I have this page where I am displaying rows with radio buttons in front of each row.
By selecting the radio for the second row, I am trying to get the id of that row which is in the variable
$row['class_id'] (8)
. The same selecting the first row I am trying to get the id of 1.Doing this having displayed another table “members” I can select one row in the same way and get member_id. Getting this variables, I can then pass them to a PHP function. that will basically say: the member with this id, is doing the class with this id.
Any suggestions? Is it the right approach to do this?
This is what I have for now, but it’s not getting the id of the row. How I have my code now it should display it.
<script type='text/javascript' src='//code.jquery.com/jquery-2.1.0.js'></script>
<?php
include("header.html");
include("menu.html");
?>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<h2 class="sub-header">Gym Members</h2>
<div class="row">
<div class = "col-sm-12">
<div class="table table-bordered">
<table class="table table-striped">
<thead>
<tr>
<th></th>
<th>ID</th>
<th>Type</th>
<th>Name</th>
<th>Duration</th>
<th>Location</th>
<th>Date</th>
<th>Repeat</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<?php
require_once ('database_initialisation.php');
$table2 = "clases";
$array = $admin_query->viewTableData($table2);
foreach ($array as $row)
{
echo
"<tr id = `testid`>
<td> <input type = 'radio' name = 'classRadio' id = 'classRadio' /> </td>
<td>" . $row['class_id'] . "</td>
<td>" . $row['class_type'] . "</td>
<td>" . $row['class_name'] . "</td>
<td>" . $row['class_duration'] . "</td>
<td>" . $row['class_location'] . "</td>
<td>" . $row['class_date'] . "</td>
<td>" . $row['class_repeat'] . "</td>
<td>" . $row['class_description'] . "</td>
</tr>";
} ?>
</tbody>
</table>
</div>
</div>
</div>
<div id='checkvalue'>
</div>
<script>
$('tbody').on('change', ':radio', function()
{
var $row = $(this).parent().parent();
var valueOfRadio = $('input[name=classRadio]:checked').val();
var idOfRow = $row.attr('id');
$('#checkvalue').html($('input[name=classRadio]:checked').val());
// alert($('input[name=classRadio]:checked').val());
});
</script>
</div>