0

I have

$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;

And it prints out

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
        )

)

And what I want is

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

I have tried many different things but no success. How I'll do it?

2 Answers 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);
Sign up to request clarification or add additional context in comments.

Comments

1
foreach($rows as $key => $value){
    $f[$value['PrivilageName']] = $value['hakkivarmi']
}

var_dump($f);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.