-1

我有两张桌子,

“用户”和“权限”

users 有一列:'permissions' 类型为int

权限有一列:int类型的'id'(AI)

我想选择一个用户并返回 id = 与用户 id 相同的权限列的值。

我试过这个:

$queryString = "
    SELECT 
        u.*, 
        p.value
    FROM 
        users u,
        permissions p
    WHERE 
        username = '$username' AND
        password = '" . md5( $password ) . "'
    INNER JOIN 
        user u on p.id = u.permissions
";

因此,不要返回用户:

id = 1,用户名 =“bob”,权限 = 3

它会说

权限=“管理员”

因为这是权限表中的值

4

5 回答 5

0
select u.*, p.value from users u, permissions p 
where
p.id=u.permissions
and
u.username='$username'
and
u.password='" . md5( $password ) . "'
于 2013-04-10T09:44:23.657 回答
0

你能提供你的两个表的结构吗?

我猜你的查询应该是这样的,我假设p.value包含权限的名称:

$queryString = "
SELECT 
    u.id,
    u.username,
    p.value AS permissions
FROM 
    users u
INNER JOIN
    permissions p
ON
    p.id = u.permissions
WHERE 
    username = '$username' AND
    password = '" . md5( $password ) . "'
";
于 2013-04-10T09:48:50.460 回答
0

试试看。

 $queryString = "SELECT u.*, p.value
    FROM users AS u
    INNER JOIN permissions AS p ON u.permissions = p.id
    WHERE 
       u.username = '$username' AND
       u.password = '" . md5( $password ) . "'"
于 2013-04-10T09:41:46.833 回答
0
$queryString = "
    SELECT 
        u.*, 
        p.value
    FROM 
        users u INNER JOIN 
        permissions p ON
        p.id = u.permissions
    WHERE 
        u.username = '$username' AND
        u.password = '" . md5( $password ) . "'

";
于 2013-04-10T09:37:47.003 回答
0

这应该会给你结果:

SELECT  
    p.value
FROM 
    permissions p
INNER JOIN 
    users u on p.id = u.permissions
WHERE 
    username = '$username' AND
    password = '" . md5( $password ) . "'
于 2013-04-10T09:40:13.280 回答