这是我需要从这些表中获取数据的表格。每个用户可以使用多种类型的groups
,例如 2,3,4
1)groups |gp_id|gp_name|gp_status| ------------------------------------- | 1 | Admin | Active | | 2 | R&D | Active | | 3 | Sales | Active | | 4 | IT | Active | 2)modules (FK of table parent_modules) |mod_id| mod_name| pmod_id | --------------------------------------------- | 1 | name1 | 1 | | 2 | name2 | 1 | | 3 | name3 | 2 | | 4 | name4 | 3 | | ... | name... | 3 | mod_id = 5,6,7.. and so on 3)parent_modules |pmod_id| mod_name |pmod_status| ----------------------------------------- | 1 | Contact Us | Active | | 2 | Account Settings | Active | | 3 | System Settings | Active | 4)group_details (FK of table groups) (FK of table modules) |gpd_id | gp_id | mod_id | base_gpd_rule_view/edit/update/insert | ----------------------------------------------------------------------- | 1 | 3 | 1 | on | | 2 | 3 | 2 | on | | 3 | 3 | 3 | | | 4 | 3 | 4 | | 5 | 3 | 5 | on | | 6 | 3 | 6 | | 7 | 3 | 7 | | 8 | 4 | 6 | | 9 | 4 | 7 | on | | 10 | 4 | 8 | on |
我必须只选择一次来自group_details
的重复结果,这就是我想要的结果。
| gp_id | mod_id | ---------------------------------------------- | 3 | 1 | | 3 | 2 | | 3 | 3 | | 3 | 4 | | 3 | 5 | | 3 | 6 | | 3 | 7 | | 4 | 8 |
到目前为止,这是我在查询中所做的,但它向我显示了重复记录。
//get user groups store in database. example group in database:2, 3, 4
$GroupList = explode(", ", $UserDetail['u_group']);
foreach($GroupList as $a)
{
$getParentModuleSQL = base_executeSQL("SELECT * FROM parent_modules WHERE pmod_status<>'Disable'" );
$count1 = base_num_rows($getParentModuleSQL);
while($ParentModuledata_row = base_fetch_array($getParentModuleSQL))
if ($count1!= 0)
{
base_executeSQL("SELECT gp.gp_id AS ID FROM group_details AS gp, modules AS m WHERE m.pmod_id =". $ParentModuledata_row['pmod_id'] ." AND gp.gp_id=". $a ." AND gp.mod_id = m.mod_id" AND (base_gpd_rule_view='on' OR base_gpd_rule_add='on' OR base_gpd_rule_edit='on' OR base_gpd_rule_delete='on') GROUP BY gp.mod_id);
}
}
答案 0 :(得分:0)
我仍然不明白你的问题。如果你想要gp_id可以访问的所有模块 - select * from group_details where gp_id = XX
。如果您只想要每个模块,select * from modules
。