I have a php and SQL code I use to extract data into a datalist
HTML with input
.
The code is fairly generic and should be know to everyone:
<datalist id="FindPlace">
<option hidden></option>
<?php
$sql = "SELECT IDPlace, Place_Name, FKCity FROM Places WHERE Place_Name <> '' ORDER BY Place_Name";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<option>" . $row["Place_Name"] . "</option>";
}
}
?>
</datalist>
I've tried to use LIMIT
, but it hides every other result, where in I need to have them all usable, just not showing everything when I click on the input
but only like first 10 options.
I also tried to insert something like $counter
in php code between while
and echo
like this:
<?php
$sql = "SELECT IDPlace, Place_Name, FKCity FROM Places WHERE Place_Name <> ''
ORDER BY Place_Name";
$counter = 10;
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
if ($row < $counter) {
echo "<option>" . $row["Place_Name"] . "</option>";
}
else {
break;
}
}
}
?>
And it didn't work. I don't really know how to use JQuery so it would be preferable to not use it, maybe there's a command I don't know, or some trick?