普通网友 2015-05-21 10:10
浏览 36

使用Jquery自动完成功能的Php Mysql搜索

I need to display search results using jQuery Autocomplete feature, I have to display results like this site when searching on brand name.

I have categories in table, when searching with brand name results should be display like below

Example: I am searching for Samsung. Results should be show like below

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

I have provided table image for understanding easy. If user type brand name that brand name should bring parent categories under list. In this image samsung name had two parent categories one is Mobiles and another is Tablets.

I am using this to get results but only category names displaying.

$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

  • 写回答

1条回答 默认 最新

  • doufangmu9087 2015-05-21 10:36
    关注

    You are assigning both value and label to == $row['name']. Label should be set to equal the parent category field of your table.

    This:

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

    Should become:

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

    EDIT: changed wording + 'label' value

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog