Created
March 11, 2019 14:44
-
-
Save hans2103/c24e0115ed515bd870e64769465f574a to your computer and use it in GitHub Desktop.
RSForm Pro generate dropdown items from DB - title from given category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//<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