Jump to content

Recommended Posts

Im making a simple(ish) user auth system.

Where modules have either 2 levels of admin access (some only have 1)

 

This is the table that stores the permission types

 

CREATE TABLE IF NOT EXISTS `sys_modulepermission` (
  `sysperid` int(10) NOT NULL AUTO_INCREMENT,
  `moduleid` int(10) NOT NULL,
  `module` varchar(50) NOT NULL,
  `allowadmin` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`sysperid`)
) 

 

Some sample data

INSERT INTO `sys_modulepermission` (`sysperid`, `moduleid`, `module`, `allowadmin`) VALUES
(1, 4, 'php', 0),
(2, 5, 'tpl', 0),
(3, 5, 'tpl_admin', 0),
(4, 7, 'users', 0),
(5, 7, 'users_admin', 0),
(6, 9, 'content', 0),
(7, 10, 'news', 0);

 

You will notice how tpl and tpl_admin, these are the same module. Same applies to users and users_admin but the others are 1 level of admin only.

 

Also this is the table sys_module which basically stores the different modules

CREATE TABLE IF NOT EXISTS `sys_module` (
  `moduleid` int(10) NOT NULL AUTO_INCREMENT,
  `modulename` varchar(100) NOT NULL,
  `moduleold` varchar(50) NOT NULL,
  `dirfolder` varchar(100) NOT NULL,
  `active` tinyint(1) NOT NULL,
  `static` tinyint(1) NOT NULL,
  PRIMARY KEY (`moduleid`),
  UNIQUE KEY `moduleid` (`moduleid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;

--
-- Dumping data for table `sys_module`
--

INSERT INTO `sys_module` (`moduleid`, `modulename`, `moduleold`, `dirfolder`, `active`, `static`) VALUES
(4, 'System', 'php', '/', 1, 1),
(5, 'Templates', 'tpl', '/', 1, 1),
(7, 'Users', 'users', '/', 1, 1),
(9, 'Content', 'content', 'content', 1, 1),
(10, 'News', 'news', 'news/', 1, 0);

 

So my current mysql statement is

select * from `sys_modulepermission` 
join `sys_module`
on `sys_modulepermission`.`moduleid` = `sys_module`.`moduleid`

 

But what I haven't got a clue how to do is get a result like this where when I run this statment through a while loop I get each module listed with its relevant permission values

 

First column is modulename from sys_module

Second column is module from sys_modulepermission

Third column is also module from sys_modulepermission but from a different row

 

System - php

Templates - tpl - tpl_admin

Users - users - users_admin

Content - content

News - news

 

Does this make sense? is it at all possible?

Link to comment
https://forums.phpfreaks.com/topic/177020-joining-records-based-on-the-relations/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.