0

我有

$query = "SELECT
PrivilageName,
PrivilageExp,
'true' hakkivarmi
FROM users
natural join usermemberships
natural join groupprivileges
natural join `privileges`
where UserID = '2' ";

$result = mysqli_query($link, $query);

$rows = Array();
while($row = mysqli_fetch_assoc($result)) {
    array_push($rows, $row);
}

print_r($rows);exit;

它打印出来

Array
(
    [0] => Array
        (
            [PrivilageName] => AddBuilding
            [PrivilageExp] => Bina Ekleme
            [hakkivarmi] => true
        )

    [1] => Array
        (
            [PrivilageName] => RemoveBuilding
            [PrivilageExp] => Bina Silme
            [hakkivarmi] => true
        )

    [2] => Array
        (
            [PrivilageName] => EditBuilding
            [PrivilageExp] => Bina Düzenleme
            [hakkivarmi] => true
        )

)

而我想要的是

Array
(
 AddBuilding => true
 RemoveBuilding => true
 EditBuilding => true
)

我尝试了很多不同的事情,但没有成功。我会怎么做?

4

2 回答 2

1
$permissions = array();

while($row = mysqli_fetch_assoc($result)) {
    $permissions[$row['PrivilageName']] = true; // You can use $row['hakkivarmi'] but it looks like it's always true based on your code
}

var_dump($permissions);
于 2013-02-11T14:13:28.153 回答
1
foreach($rows as $key => $value){
    $f[$value['PrivilageName']] = $value['hakkivarmi']
}

var_dump($f);
于 2013-02-11T14:13:55.307 回答