How to Search value from input by mysqli in database

前端 未结 3 1445
野性不改
野性不改 2020-12-22 15:39

I want to show my database value when use type first character of the value. Let me describe it with my site I have a website with homepage input where user type input as t

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-22 16:07

    check this code .i think it will help you

    
     
    
    PHP, jQuery search demo
    
    
    
    
    
     
      
     

    Search results :

    first create html and jquery code for input field which you type then call jquery function keyup which hit database using ajax method then create a php file which manage your search i create a search.php file

    connect_error) {
      die("Connection failed: " . $conn->connect_error);
      }
    
     $sql = "SELECT  filed1, field2 FROM yourtable_name WHERE match_text LIKE '%$searchquery%'";
    $result = $conn->query($sql);
    
    if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo " - Name: " . $row["filed1"]. " " . $row["field2"]. "
    "; } } else { echo "0 results"; } $conn->close(); ?>

    from this page you will get your search result and you can change it as your demand . for your check you can also add search text length if you do not search if search text length > 2 or etc

提交回复
热议问题