I have a list of files from my database. I'm looking for a way to query them. but I'm receiving an error, which is... it only display the first item if my input matches the first.
This is the form
<form>
<input type="text" placeholder="Filter" aria-label="Search"
onkeyup="myFunction()" id="myInput">
</form>
below is the php
<?php
$query = "SELECT classname,cdate FROM classnametb`";
$res = mysqli_query($db, $query);
while ($r = mysqli_fetch_assoc($res)){
$classname = $r['classname'];
$classdate = $r['cdate'];
$classdate = date("m/d/y", strtotime($classdate));
?>
<div id="myUL">
<b>
<a href="studentclass.php?course=<?php echo($classname); ?>&&cdate=<?php echo($classdate); ?>"
class="btn btn-primary btn-icon" style="width: 20% !important;">
<span class="btn-inner--text"><?php echo($classname . '(' . $classdate . ')'); ?></span>
</a>
<?php } ?>
</b>
</div>
and I have the js here
function myFunction() {
var input, filter, div, b, a, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
div= document.getElementById("myUL");
b = div.getElementsByTagName("b");
for (i = 0; i < b.length; i++) {
a = b[i].getElementsByTagName("a")[0];
txtValue = a.textContent || a.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
b[i].style.display = "";
} else {
b[i].style.display = "none";
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…