Drop down labels

QuestionsDrop down labels
Cedric asked 7 years ago

Hello Abu,
I am trying to display a drop down list showing all countries like this

$col["formatter"] = "autocomplete"; // autocomplete
$col["formatoptions"] = array("sql"=>"SELECT DISTINCT ShortCountryName as k, Two_letter_CountryCode as v from countrieslist", "update_field"=>"ep_country","search_on"=>"Two_letter_CountryCode");
$str = $g->get_dropdown_values("SELECT DISTINCT ShortCountryName as k, Two_letter_CountryCode as v from countrieslist");
$col["stype"] = "select"; // enable dropdown search
$col["searchoptions"] = array("value" => ":;".$str);
$cols[] = $col;

It only display display the value, not the label (ShortCountryName)
If I reverse ShortCountryName and Two_letter_CountryCode , it display the full country name…

Can you help?

Thanks
Cedric

3 Answers
Abu Ghufran answered 7 years ago

If you want to show both, and search in both … you can set:

$col["formatoptions"] = array("sql"=>"SELECT DISTINCT ShortCountryName as k, concat(ShortCountryName,' ',Two_letter_CountryCode) as v from countrieslist", "update_field"=>"ep_country","search_on"=>"concat(ShortCountryName,' ',Two_letter_CountryCode)");

It will now display concatenated both fields, and set country name as value of dropdown.
It will also suggest in autocomplete in both fields.

Cedric answered 7 years ago

OK that's a work around, but it will not work for me as The value that needs to be entered in the table is the Two_letter_Code only!
Just to understand why then you need to build the dropdown with key and value?

Abu Ghufran answered 7 years ago

You need to replace the '… as k' to whatever you want to save in database.
e.g. Use
Two_letter_Code as k
In both autocomplete and dropdown_select queries.

Your Answer

6 + 7 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?