1

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 Answers 3

2

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
Sign up to request clarification or add additional context in comments.

Comments

2
"SELECT concat(suburb, ' ', code) as label, suburb as value

Comments

0

try this your sql query..

SELECT suburb as label, code as value
            FROM Sheet1
            WHERE suburb like '%$t%'
            LIMIT 25

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.