Jeg har følgende kode pt.
--- Index.php ---
<?php
require ('connection.php');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
?>
<!DOCTYPE html>
<html lang="da">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<meta charset="UTF-8">
<title>Test</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/scrolling-nav.css" rel="stylesheet">
</head>
<body id="page-top" data-spy="scroll" data-target=".navbar-fixed-top">
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<li>
<a class="page-scroll" href="#page-top">Velkommen</a>
</li>
<li>
<a class="page-scroll" href="#about">Afkrydsningsliste</a>
</li>
<li>
<a class="page-scroll" href="#services">Tilføj ny spiller</a>
</li>
</ul>
</div>
</div>
</nav>
<section id="intro" class="intro-section">
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="page-header">
<h2>VELKOMMEN<br><small>Oversigt over alle klubbens træninger</small></h2>
</div>
<?php
$sql = "SELECT hold_id, count(tbl_map_medlem_hold_traeninger.id) AS antal, tbl_hold.Navn FROM tbl_map_medlem_hold_traeninger JOIN tbl_hold ON tbl_hold.id = tbl_map_medlem_hold_traeninger.hold_id GROUP BY Navn";
$result = $conn->query($sql);
while ($row = $result->fetch_assoc()) {
echo "<div class='well well-sm'>";
echo "<b>"; echo $row['Navn']; echo "</b>";
echo " ("; if($row['antal'] > 1) { echo $row['antal']; echo " tilmeldte spillere)"; } else { echo $row['antal']; echo " tilmeldt spiller)"; }
echo "</div>";
}
?>
</div>
</div>
</div>
</section>
<section id="about" class="about-section">
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="page-header">
<h2>AFKRYDSNINGSLISTE<br><small>Vælg træning - Sørg for afkrydsning af alle spillere</small></h2>
</div>
<?php
$sql = "SELECT * FROM tbl_hold";
$rs = $conn->query($sql);
echo '<select class="form-control" name="hold" id="hold">';
echo "<option value='0'>Vælg træning</option>";
while ($row = $rs->fetch_assoc()) {
echo "<option value='" . $row['id'] . "'>" . $row['Navn'] . "</option>";
}
echo "</select>";
?>
<br><br>
<table class="table" style="width:100%" id="myTable">
<thead class="thead-inverse">
<tr>
<th>#</th>
<th>Navn</th>
<th>Alder</th>
<th>Aldersgruppe</th>
<?php
$sql = "SELECT * FROM `tbl_traeninger` ORDER BY Dato DESC LIMIT 2";
$rs = $conn->query($sql);
while ($row = $rs->fetch_assoc()) {
echo "<th>" . date('d-m-Y', strtotime($row['Dato'])) . "</th>";
}
?>
<th>Antal</th>
</tr>
</thead>
<tbody>
<!-- indhold kommer via AJAX -->
</tbody>
</table>
</div>
</div>
</div>
</section>
<div class="noprint" style="height:100%"><!-- Services Section -->
<section id="services" class="services-section">
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="page-header">
<h2>TILFØJ NY SPILLER<br><small>Udfyld alle informationer for at tilføje en ny spiller</small></h2>
</div>
<br><br>
<form class="form-horizontal" action="" method="POST">
<div class="form-group">
<label class="col-sm-2 control-label">Navn</label>
<div class="col-sm-10">
<input class="form-control" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Fødselsdato</label>
<div class="col-sm-10">
<input class="form-control" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Træninger</label>
<div class="col-sm-10">
<select id="dates-field2" class="multiselect-ui form-control" multiple="multiple">
</select>
</div>
</div>
<div style="float:right;"><button type="submit" id="submit" name="submit" class="btn btn-primary">Tilføj ny spiller</button></div>
</form>
</div>
</div>
</div>
</section></div>
<script src="
https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> <script src="
https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> <script src="
https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#hold").change(function () {
var js_ar = new Array();
var url = "request_medlemmer.php";
var params = "hold=" + $("#hold").val();
$.ajax({
type: "GET",
url: url,
data: params,
success: function (data) {
//console.log(data);
js_ar = $.parseJSON(data);
var table = '';
$.each(js_ar, function (index, item) {
table += '<tr>';
table += '<td align="left">' + item.id + '</td>';
table += '<td align="left">' + item.fornavn + ' ' + item.efternavn + '</td>';
table += '<td align="left">' + item.age + '</td>';
table += '<td align="left">' + item.age_group + '</td>';
table += '<td align="left"> <input type="checkbox" name="dates" value=""></td>';
table += '<td align="left"> <input type="checkbox" name="dates" value=""></td>';
table += '<td align="left">' + item.antal + '</td>';
table += '</tr>';
});
$('#myTable tr').slice(1).remove();
$('#myTable tr:last').after(table);
}
});
});
});
</script>
<!-- jQuery -->
<script src="js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
<!-- Scrolling Nav JavaScript -->
<script src="js/jquery.easing.min.js"></script>
<script src="js/scrolling-nav.js"></script>
<script type="text/javascript">
$(function() {
$('.multiselect-ui').multiselect({
includeSelectAllOption: true
});
});
</script>
</body>
</html>
--- Request_medlemmer.php ---
<?php
require("connection.php");
$arr = array();
$id = (int) $_GET['hold'];
$sql = "SELECT DISTINCT tbl_medlem.id, tbl_medlem.fornavn, tbl_medlem.efternavn, tbl_medlem.dob FROM tbl_map_medlem_hold_traeninger JOIN tbl_medlem ON tbl_medlem.id = tbl_map_medlem_hold_traeninger.medlem_id WHERE tbl_map_medlem_hold_traeninger.hold_id =" . $id;
$rs = $conn->query($sql);
while ($row = $rs->fetch_assoc()) {
$ar = array();
$ar['id'] = $row['id'];
$ar['fornavn'] = $row['fornavn'];
$ar['efternavn'] = $row['efternavn'];
$from = new DateTime($row['dob']);
$to = new DateTime('today');
$ar['age'] = $from->diff($to)->y;
$sql1 = "SELECT name FROM tbl_age_interval WHERE " . $ar['age'] . " BETWEEN age_from AND age_to";
$rs1 = $conn->query($sql1);
if ($rs1) {
$row1 = $rs1->fetch_assoc();
$ar['age_group'] = $row1['name'];
} else {
$ar['age_group'] = "unknown";
}
$sql2 = "SELECT count(id) AS antal FROM tbl_map_medlem_hold_traeninger where hold_id = ".$id." and medlem_id = ".$ar['id'];
$rs2 = $conn->query($sql2);
$row2 = $rs2->fetch_assoc();
$ar['antal'] = $row2['antal'];
$arr[] = $ar;
}
echo json_encode($arr);
?>
Jeg ved ikke hvad der vil være bedst/nemmest?