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 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao