Jump to content

how to create Searchable dropdown that echeos data from a database


morena

Recommended Posts


 

good day, i have a programme built in php and html which i want to incorporate a searcheble dropdown menu in it,i found this link on how to do it using jquery http://jsearchdropdown.sourceforge.net/

but the problem is that one used option tags around all of thier options, which is something i can not do because my dropdown will hold around 70000 options.

here is my php code:

<?php
include_once
'dbConfig.php';
$query="SELECT * FROM medications";
$result= $con->query($query);
?>
<select id="nol" style="width: 40%;" name="disease" required="true" data-toggle="tooltip" data-original-title="medications" class="date-picker form-control col-md-7 col-xs-12" data-rel="chosen">
<option value="">Select Disease</option>
<?php while ($row=$result->fetch_array(MYSQLI_ASSOC)) { ?>
<option value="<?php echo $row['ICD10']?>"><?php echo $row['diagnosis'];?> </option>
<?php } ?>
</select>

 

so what i need help with to be make that dropdown have a search feature or function but do not know how to doit, also because the data in the dropdown is being populated from the database not hard coded in html as options

Edited by morena
Link to comment
Share on other sites

Instead of a list of 70,000 items it sounds like you might need some sort of cascading selection.

 

So you first select a category, which gives you a list of sub-categories

Then select a sub-category which can then give you another shorter list.

 

... and so on until you have narrowed the options down to a manageable sized list.

 

The way to accomplish this is with AJAX, passing the category and receiving the shorter list etc.

Link to comment
Share on other sites

What you are looking for is called "Auto Complete". It is the same thing google does. It uses AJAX. Google is your friend. I easily found numerous examples. There is no need split the data unless you want to get results by category like @Barand said. The only thing with categories is a medicine can fall into numerous categories. If you do not have that all mapped the user may have trouble drilling down to a specific medicine. A single autocomplete is best if they already know the name of the medicine. You may actually want both options, one if you know the name, the chained select if you are trying to find a type of medicine.

 

https://www.google.com/search?q=php+autocomplete+dropdown+from+database

Edited by benanamen
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.