Skip to content

Instantly share code, notes, and snippets.

@hans2103
Created March 11, 2019 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hans2103/c24e0115ed515bd870e64769465f574a to your computer and use it in GitHub Desktop.
Save hans2103/c24e0115ed515bd870e64769465f574a to your computer and use it in GitHub Desktop.
RSForm Pro generate dropdown items from DB - title from given category
//<code>
use Joomla\CMS\Factory;
$catid = 345; // fake cat id
$items = array();
$items[] ="|Select";
$db = Factory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName(array('id','title)));
$query->from($db->quoteName('#__content'));
$query->where($db->quoteName('catid') . " = " . $db->quote($catid));
$db->setQuery($query);
$results = $db->loadObjectList();
foreach ($results as $result) {
$value = $result->id;
$label = $result->title;
$items[] = $value.'|'.$label;
}
$items = implode("\n", $items);
return $items;
//</code>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment