普通网友 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 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题