English 中文(简体)
用户和许可
原标题:users and permissions

我想给一些用户某些许可。 这是最好的办法吗? 我不想让诸如行政、主持人、正常等等的团体参与进来。 我希望能够让一个用户能够进入新闻发布站,另一个用户则产生民意测验,也许另一个用户会删除民意测验。

我这样想:

CREATE TABLE `users` (
`id` mediumint(8) unsigned NOT NULL,
`username` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
)

CREATE TABLE `user_permissions` (
`id` mediumint(8) unsigned NOT NULL,
`user_id` mediumint(8) unsigned NOT NULL DEFAULT  0 ,
`can_post_news` tinyint(1) NOT NULL DEFAULT  0 ,
`can_delete_topics` tinyint(1) NOT NULL DEFAULT  0 
 ........
)

而且 每一页都需要检查:

$sql = mysql_query("SELECT * FROM user_permissions WHERE user_id = $loggedinuser");
$row = mysql_fetch_assoc($sql);

if ($row[ can_delete_topics ] == 1) {
mysql_query("delete from topics....");
}

另一问题: 我能否发挥检查守则的作用,因此我不需要每页的这种简单代码? (如果职能不错)

利用我的英语,我做最出色的工作。

增 编

问题回答

更好的方式是(利用邮资)

CREATE TABLE users (
    id      SERIAL, -- autoincrementing int
    ...
)

CREATE TABLE permissions (
    id      SERIAL,
    name    VARCHAR(255) NOT NULL,
    ...
)

create table users_permissions (
    id_user REFERENCES users(id),
    id_permission REFERENCES permission(id),
    UNIQUE(id_user, id_permission)
)

然后在<代码>用户_permissions表中对浏览进行核对。

对您的第二个问题来说,情况已经更长。 对于上述法典,你必须检查用户是否拥有执行特定职能的适当许可。 对于那些能够记住的网址(即:它正确吗?)来说,它是一个有用的法典图书馆。 还有一个庞大的班级存放处,但我可以记住其名称。

<><>Edit>:

i 查询网站:http://www.phpques.org/。 如何记住......





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签