duan2477 2012-05-18 05:34
浏览 53
已采纳

显示数据库表中的两个字段以填充jquery自动完成

I have implemented a jquery ui autocomplete with data from database. Right now what I have done is only to display one field. Let's say for example I have a database:

| id | suburb | code
  0     DAR      10
  1     ASD      20
  2     DEF      30
and so on....

my html code:

<form id="auto_test">
<label for="tags">Tags: </label>
<input id="tags" type="text" name="tags" />
<input type="button" id="auto_test_btn" value="save" />

jquery:

jQuery("#tags").autocomplete({
        source: "<?php echo WP_PLUGIN_URL.'/plugin_name/php_file.php'?>"
    });

php :

$t = $_GET['term']; 
$code = $wpdb->get_results(
        "SELECT suburb as label, suburb as value
        FROM Sheet1
        WHERE suburb like '%$t%'
        LIMIT 25
        ",ARRAY_A
        );  
echo(json_encode($code));

The autocomplete displays only the 'suburb' for it is defined as label. What I wanted to do is to display both the suburb and the code.

What would be the nice thing to do?

  • 写回答

3条回答 默认 最新

  • dpd7195 2012-05-18 05:40
    关注

    You can concatenate the columns (with an appropriate separator) within your SQL select statement, perhaps something like this:

    "SELECT Concat(suburb, ' ', code) as label, suburb as value
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用