Mysql php search using jquery autocomplete

I need to display search results using the jQuery autocomplete function, I have to display results similar to a site when searching by brand name.

I have categories in the table when a search with brand results should be displayed as shown below

Example: I'm looking for Samsung. Results should be shown below.

<pre>
Samsung
 in Mobiles
 in Tablets
</pre>

I found a table image for easy understanding. If the custom brand name type should contain a list of parent categories. In this image, the name samsung had two parent categories: one for mobile and the other for tablets.

I use this to get results, but only category names are displayed.

$term = $_GET["term"];
    $json=array();
    $st = $db->prepare("select * from category where name like '".$term."%' " );
    $st->execute();
    while($row = $st->fetch(PDO::FETCH_ASSOC))
    {
    $json[]=array(
                'value'=> $row["name"],
                'label'=>$row["name"]
                    );
    }
    echo json_encode($json); 

Table image

+4
source
1

== $row ['name']. .

:

$json[]=array(
            'value'=> $row["name"],
            'label'=>$row["name"]
                );
}

:

$json[]=array(
            'value'=> $row["name"],
            'label'=>$row["url"]
                );
}

EDIT: + "label"

+1

Source: https://habr.com/ru/post/1589180/


All Articles