我在Joomla中使用RSform創建表單來輸入數據。表單有一個下拉菜單來選擇用戶,並且該字段使用表單中的以下代碼獲取數據。按照RSform中的用戶組過濾
我想要做的是讓列表只顯示特定用戶組中的用戶名稱。 實際用戶存儲在表#__users
中,其唯一標識爲id
,這些組存儲在表#__usergroups
中,唯一標識也被稱爲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;
這太好了我會放棄它,非常感謝:) – mnunan 2014-09-23 13:05:46
這工作完美,感謝大家的快速和偉大的幫助:) – mnunan 2014-09-23 13:09:34
你更歡迎。很高興幫助:) – Lodder 2014-09-23 13:09:58