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 に答える