how to filter search result with dropdown list in php

1.1k views Asked by At

i am doing a webpage project. it have student role and teacher role. when teacher signed in their account, they are able to search students by name.

but many students can have the same name, i don't know how to code this part where when teacher typed student's name in the search bar, the result should filter all students' name. for example, teacher is searching for "john tan" then all the similar names should be displayed in the dropdownlist and filter all the results from the database."john tan mingjie" or "john lim"

thank you whoever is helping me with this!!!

2

There are 2 answers

2
mariobgr On

You can use Select2 - a free jQuery plugin.

https://select2.github.io/examples.html

$(document).ready(function() {
  $(".js-example-basic-single").select2();
});

<select class="js-example-basic-single">
  <option value="1">James Raynor</option>
  <option value="2">Alexei Stukov</option>
    ...
  <option value="9999">Sarrah Kerrigan</option>
</select>

Easy as that :)

0
Sivabalan On

You can use the LIKE in the mysql command

    $query = $pdo->prepare("SELECT * FROM student_details WHERE student_name = :filter");
    $query->bindValue(":filter", $_REQUEST['name'] . "%");
    $query->execute();

I think this will help you.