Server side søk
This commit is contained in:
parent
9a0dd90bd6
commit
a18c29cbe6
@ -47,7 +47,7 @@
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<button onmousedown="update()">Oppdater tabell</button>
|
<button onmousedown="update()">Oppdater tabell</button>
|
||||||
<input id="search" type="number" class="form-control" onkeyup="filterTable()" placeholder="Søk">
|
<input id="search" type="number" class="form-control" onkeydown="update()" placeholder="Søk etter startnummer">
|
||||||
<br>
|
<br>
|
||||||
</div>
|
</div>
|
||||||
<table id="runners"></table>
|
<table id="runners"></table>
|
||||||
@ -90,38 +90,12 @@ function register_runner(id) {
|
|||||||
update()
|
update()
|
||||||
document.getElementById("search").focus()
|
document.getElementById("search").focus()
|
||||||
};
|
};
|
||||||
function filterTable() {
|
|
||||||
var input, filter, table, tr, td, i, txtValue;
|
|
||||||
input = document.getElementById("search");
|
|
||||||
filter = input.value;
|
|
||||||
table = document.getElementById("runners").getElementsByTagName("tbody")[0];
|
|
||||||
if (!table) {
|
|
||||||
setTimeout(filterTable, 100);
|
|
||||||
}
|
|
||||||
tr = table.getElementsByTagName("tr");
|
|
||||||
|
|
||||||
if (filter == "") {
|
|
||||||
for (i = 0; i < tr.length; i++) {
|
|
||||||
tr[i].style.display = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
for (i = 0; i < tr.length; i++) {
|
|
||||||
td = tr[i].getElementsByTagName("td");
|
|
||||||
txtValue = td[0].textContent;
|
|
||||||
if (txtValue == filter) {
|
|
||||||
tr[i].style.display = "";
|
|
||||||
} else {
|
|
||||||
tr[i].style.display = "none";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
const table = document.getElementById("runners");
|
const table = document.getElementById("runners");
|
||||||
control = get_control();
|
control = get_control();
|
||||||
let request = new Request(`table.php?registrering,`+control);
|
filter = document.getElementById("search").value;
|
||||||
|
let request = new Request(`table.php?type=registrering&control=`+control+`&filter=`+filter);
|
||||||
fetch(request)
|
fetch(request)
|
||||||
.then((response) => response.text())
|
.then((response) => response.text())
|
||||||
.then((text) => {table.innerHTML = text;})
|
.then((text) => {table.innerHTML = text;})
|
||||||
|
31
table.php
31
table.php
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
date_default_timezone_set('UTC');
|
date_default_timezone_set('UTC');
|
||||||
$GLOBALS['start_time'] = DateTime::createFromFormat(DateTime::ISO8601, "2024-10-08T08:07:32+01");
|
$GLOBALS['start_time'] = DateTime::createFromFormat(DateTime::ISO8601, "2024-11-01T10:07:32+01");
|
||||||
$GLOBALS['number_of_controls'] = 3;
|
$GLOBALS['number_of_controls'] = 3;
|
||||||
|
|
||||||
//declare(strict_types=1);
|
//declare(strict_types=1);
|
||||||
@ -84,6 +84,15 @@ function cmp_course(Runner $a, Runner $b) {
|
|||||||
return strcmp($a->course, $b->course);
|
return strcmp($a->course, $b->course);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function filter_runners(Runner $runner, $id) {
|
||||||
|
if ($runner->id == $id) {
|
||||||
|
return True;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$runners = [];
|
$runners = [];
|
||||||
$csv_runners = file_get_contents("db.csv");
|
$csv_runners = file_get_contents("db.csv");
|
||||||
@ -117,11 +126,23 @@ for ($i = 0; $i < count($timings); $i++) {
|
|||||||
|
|
||||||
|
|
||||||
if (!isset($query)){
|
if (!isset($query)){
|
||||||
$query = explode(",",$_SERVER['QUERY_STRING']);
|
parse_str($_SERVER['QUERY_STRING'], $query);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($query[0] == "registrering"){
|
if ($query["type"] == "registrering"){
|
||||||
$matpost = $query[1];
|
$matpost = $query["control"];
|
||||||
|
$runners_filtered = [];
|
||||||
|
if ($query["filter"]) {
|
||||||
|
for ($i = 0; $i < count($runners); $i++) {
|
||||||
|
if (filter_runners($runners[$i], $query["filter"])) {
|
||||||
|
array_push($runners_filtered, $runners[$i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$runners = $runners_filtered;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
echo(" <thead><tr>
|
echo(" <thead><tr>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
<th>Navn</th>
|
<th>Navn</th>
|
||||||
@ -158,7 +179,7 @@ if ($query[0] == "registrering"){
|
|||||||
}
|
}
|
||||||
echo("</tbody>");
|
echo("</tbody>");
|
||||||
}
|
}
|
||||||
elseif ($query[0] == "paameldte") {
|
elseif ($query["type"] == "paameldte") {
|
||||||
usort($runners, "cmp_course");
|
usort($runners, "cmp_course");
|
||||||
|
|
||||||
$kadaverløpere = 0;
|
$kadaverløpere = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user