Jump to content

jquery autocomplete - pass just one value, not the entire array


ramone_johnny

Recommended Posts

I'm hoping someone can help me out with this, I'm relatively new to PHP as my background is ASP, so I'm a bit stuck.
 

I'm using the following code as demonstrated here htmlblog.us/jquery-autocomplete
 

...and I've customized it (slightly) to pull information from my mysql database.

 

Everything is working fine, however, my problem is that when the user selects a specific location from the dropdown, its passing over the suburb, the state, and the postcode. I only want to pass over the postcode value, so I can handle the results easily on the search results page.

 

If I use this....

while( $row = mysql_fetch_array($rs, MYSQL_ASSOC) )
{
    $data[] = array(
        'label' => $row['pcode_area'] .', '. $row['pcode_state'] .' '. $row['pcode_postcode'] ,
        'value' => $row['pcode_area'] .', '. $row['pcode_state'] .' '. $row['pcode_postcode'] .'; '
    );

It posts this to my search results page...

 

(eg showing a search for Brisbane, QLD; 4000)

 

Array ( [zipsearch] => BRISBANE, QLD 4000; ) 

I only want the postcode value.

 

So instead, I would like ...

 

Array ( [zipsearch] => 4000; ) 

I tried doing this....

 

while( $row = mysql_fetch_array($rs, MYSQL_ASSOC) )
{
    $data[] = array(
        'label' => $row['pcode_area'] .', '. $row['pcode_state'] .' '. $row['pcode_postcode'] ,
        'value' => $row['pcode_postcode'] .'; '
    );

..which passes over just the postcode like I want, but that's no good because upon selection, the suburb and state disappear leaving just the postcode in the selection box, which may confuse people.

 

I'm pretty sure there's an easy way to do this, but being new to PHP, I'm a bit lost.

 

I would really appreciate some help with this, as I'd like to get this sorted ASAP.

 

Thank you.

John

Edited by ramone_johnny
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.