【发布时间】:2014-09-23 11:55:02
【问题描述】:
我在 Joomla 中使用 RSform 来创建一个表单来输入数据。表单有一个下拉菜单来选择用户,该字段使用表单中的以下代码获取数据。
我想做的是让列表只显示特定用户组中的用户名。
实际用户存储在表#__users 中,唯一ID 称为id,组存储在表#__usergroups 中,唯一ID 也称为id。我希望能够过滤列表以仅显示用户组 2 中的那些用户。
有人可以帮忙吗?
提前致谢
// Prepare the empty array
$items = array();
// Prepare the database connection
$db = JFactory::getDbo();
// Keep this if you'd like a "Please select" option, otherwise comment or remove it
$items[] = "|Please Select[c]";
// Run the SQL query and store it in $results
$db->setQuery("SELECT id, name, email FROM #__users");
$results = $db->loadObjectList();
// Now, we need to convert the results into a readable RSForm! Pro format.
// The Items field will accept values in this format:
// value-to-be-stored|value-to-be-shown
// Eg. m|M-sized T-shirt
foreach ($results as $result) {
$value = $result->name;
$label = $result->name;
$items[] = $value.'|'.$label;
}
// Multiple values are separated by new lines, so we need to do this now
$items = implode("\n", $items);
// Now we need to return the value to the field
return $items;
【问题讨论】: