• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Can wildcards be used in dropdown field item PHP ?

Can wildcards be used in dropdown field item PHP ? 9 years 6 months ago #32715

I am trying to make a form with the following dropdown fields:

Country
State / Province
City

I have a row in my database with a list of all cities in the world, I would like to populate the City dropdown field with ONLY cities that are in the country and or state/province that the user selects. For example, If the user selects Ontario, Canada they should only see cities that are in Ontario, Canada. The dropdown currently works but its being populated with all cities in the database. I have tried adding a custom PHP query in the item section of the dropdown field (see below), but this did not work. Please help. Thanks in advance.

My database looks similar to this:

fieldid | value

|
33 | ON|Toronto
| ON|Mississauga
| ON|Brampton


//<code>
$items = array();

$db = JFactory::getDbo();

$items[] = "|Please Select[c]";

// Used a wildcard to target only cities that begin with ON
$db->setQuery("SELECT value FROM #__acymailing_fields WHERE fieldid = 33 AND value LIKE "ON%");
$results = $db->loadObjectList();

foreach ($results as $result) {
$value = $result->value;
$items[] = $value;
}

$items = implode("\n", $items);

return $items;
//</code>
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!