Skip to main content

autosearch in html css javascript and php

 Here the first page index.php 


<!DOCTYPE html>
<html>
<head>
    <title>Autocomplete Select Option from MySQL Database</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
    <h2>Autocomplete Select Option from MySQL Database</h2>
    <form>
        <label for="autocomplete">Search:</label>
        <div style="display: flex; flex-direction:column">
        <input type="text" id="autocomplete" name="autocomplete">
        <select id="selectOption" style="display:none;" size="15" style="width:fit-content"></select>
        </div>
    </form>

    <script>
        $(document).ready(function(){
            $('#autocomplete').on('input', function(){
                var inputVal = $(this).val();
                $.ajax({
                    type: "POST",
                    url: "material.php",
                    data: {term: inputVal},
                    success: function(data){
                        $('#selectOption').html(data).show();
                    }
                });
            });

            $('#selectOption').on('change', function(){
                $('#autocomplete').val($(this).val());
                $(this).hide();
            });
        });
    </script>
</body>
</html>


here the second page for the finding the item in php

<?php
include("connect.php");

// Get input value
$term = $_POST['term'];

// Query database
$sql = "SELECT * FROM materialent WHERE matedesc LIKE '%$term%'";
$result = $store->query($sql);

// Generate options
$options = '';
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $options .= '<option value="' . $row['matedesc'] . '">' . $row['matedesc'] . '</option>';
    }
}

// Return options
echo $options;

$store->close();
?>


so finally get the access of PHP data

Comments

Popular posts from this blog

How to add the treeview numbers to get the grand total in tkinter entry box

 in this blog we are going to know about the adding of the integers in the treeview and get the total in the entry box of tkinter so here is the image first so the coding to do such things are here as follow but here is the condition that pls make assured that the state of entry box is disabled.......      for child in my_tree1 . get_children ():         e2l . config ( state = "normal" )         b1 += float ( my_tree1 . item ( child , "values" )[ 3 ])         var2 . set ( b1 )         e2l . config ( state = "disable" )      l2l = Label ( ento , text = "Purnea-2" , width = 8 )      l2l . grid ( row = 0 , column = 1 )     e2l = Entry ( ento , textvariable = var2 , state = "disable" , width = 8 )     e2l . grid ( row = 1 , column = 1 )