当前位置: 动力学知识库 > 问答 > 编程问答 >

html - Select Options more than 50,000 rows

问题描述:

I have a database which got about 50 000 records. all is information of business partners.

I currently using

<select name="selection">

-- some while loop

<option></option> (repeat about 50,000 times)

-- end while loop

</select>

The issue is whenever I click on my dropdown, my browser will hang and crash. I think the records are too much.

For such cases, what is the best recommended implementation that can allow user to choose from the list of choice that is retrieve from database (about 50,000 choices) .

I need to do a form post to retrieve the ID of the selected option.

网友答案:

Add a search functionality to this. First step is to get the input which will act as the search term.

<input id="search-term" type="text">

You're probably doing a SQL statement like

SELECT * 
FROM business_partners;

to get generate your select options right now. With the new search term, you'd change the SQL statement to something like:

SELECT * 
FROM business_partners
WHERE name LIKE '%search_term%'
LIMIT 100;

search_term above would be the input value the user entered. Your user will still need a somewhat unique search term to find the correct business partner since there is a limit of 100 items being returned in the results - but you can increase this depending on your preference.

分享给朋友:
您可能感兴趣的文章:
随机阅读: