作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在 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;
最佳答案
您需要将用户映射到 usergroup_map
表,如下所示:
$groupID = 2;
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('a.*')
->from($db->quoteName('#__users') . ' AS a')
->join('LEFT', $db->quoteName('#__user_usergroup_map') . 'AS map2 ON map2.user_id = a.id')
->group($db->quoteName(array('a.id', 'a.username')))
->where('map2.group_id = ' . (int) $groupID);
$db->setQuery($query);
$results = $db->loadObjectList();
foreach($results as $result) {
echo $results->username;
}
这将只显示属于当前设置为 2 的 $groupID
的用户的所有用户名,您可以相应地更改它。
所以你的最终和完整代码将是这样的:
$items = array();
$groupID = 2;
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('a.*')
->from($db->quoteName('#__users') . ' AS a')
->join('LEFT', $db->quoteName('#__user_usergroup_map') . 'AS map2 ON map2.user_id = a.id')
->group($db->quoteName(array('a.id', 'a.username')))
->where('map2.group_id = ' . (int) $groupID);
$db->setQuery($query);
$results = $db->loadObjectList();
$items[] = "|Please Select[c]";
foreach ($results as $result) {
$value = $result->username;
$label = $result->username;
$items[] = $value.'|'.$label;
}
$items = implode("\n", $items);
return $items;
关于php - 在 RSform 中按用户组过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25994468/
我在 Joomla 中使用 RSform 创建一个表单来输入数据。该表单有一个用于选择用户的下拉菜单,该字段使用表单中的以下代码获取数据。 我想做的是让列表只显示特定用户组中的用户名。实际用户存储在表
因此,我在 Joomla 的 RSForm Pro 中有此注册表单,并且有两个下拉列表。一个从 mySQL 获取美国各州,一个应该从该州获取城市/县。问题是,我不知道如何检查用户在第一个下拉列表中选择
请帮我解决这个问题。我正在使用 RSForm joomla 2.5,在前端显示提交时,出现的详细信息位于我不想要的 anchor 标记上。谁能建议我如何禁用链接。 谢谢你,钱南 最佳答案 很难清楚地理
我是一名优秀的程序员,十分优秀!