简体   繁体   English

填充数据列表花费的时间太长。 用户在输入字段中输入几个字母后如何开始填充

[英]Populating datalist takes too long. How to start populating after user enters a few letters in the input field

I have a database table with cities of the world. 我有一个包含世界各城市的数据库表。 All in all there are over 100 000 entries. 总共有超过100 000个条目。 The user should choose via input text field and the datalist one of those entries. 用户应通过输入文本字段和数据列表选择这些条目之一。 Right now I populate the datalist options via PHP: 现在,我通过PHP填充数据列表选项:

<input type='text' list='location' placeholder='Location'>
<datalist id='location'>
    <?php include("query.php");
        while($row = $result->fetch_assoc()) {
            echo "<option data-value='". $row['CityName']. "'>". $row['CityName']. "</option>";
    };?>
</datalist>

However, due to the large amount of rows it takes too long to load these options. 但是,由于行数很大,因此加载这些选项花费的时间太长。 Therefore I would like to start the populating procedure only when the user entered at least 3 letters in the input field (like on this website ). 因此,仅当用户在输入字段中输入至少3个字母时(如在本网站上 ),我才想开始填充过程。 But my problem right now is that I don't know how to combine a javascript if clause and the php code as the php is loaded before I can use javascript. 但是我现在的问题是我不知道如何结合javascript if子句和php代码,因为在我可以使用javascript之前已加载了php。 How can I create this function like on the mentioned website? 我如何像提到的网站一样创建此功能?

I think that JQuery autocomplete is a complete answer. 我认为JQuery自动完成功能是一个完整的答案。 In particular the "remote datasource" case. 特别是在“远程数据源”情况下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM