How to Search value from input by mysqli in database

前端 未结 3 1424
野性不改
野性不改 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:20

    Try this

    if (isset($_POST['searchVal'])) {
    $searchquery = $_POST['searchVal']; //input for search
    
    //count table to see if any row/column has the train number
    
    $searcher = mysqli_query("SELECT COUNT(*) FROM tablename WHERE trainno LIKE '%$searchquery%'") or die("could not search");
    
    
    $count = mysqli_num_rows($searcher);
    
    if ($count == 0) {
        echo "No results found";
    } else {
    
        //while loop to select row with train name
        while($row = msqli_fetch_array($query)) {
    
            $trainnname = $row['trainname'];//name of row containing train name
    
            echo $trainname;
        }
      } 
    }
    

    Hope you understand how this works

提交回复
热议问题