I have three Table their structure is added down there. i want to show all role on one screen. and when click on one any role it will take you to next screen where (all the permission shown in check boxes) permission that is given to that role checked and other unchecked. and i want to that dynamically, as it can be given and taken by using check boxes. there check boxes should contain role_id and perm_id so it can b use for crud operations.table has many to many relation.
i have the role_id bu using the isset($_GET['role_id'])
metthod and perm_id by calling a function that will give me the perm_id
<?php if (isset($_GET['role_id'])) {
$role_id = $_GET['role_id'];
} ?>
user_permission.php page
<?php $row = $role->allPermission($role_id); if(!empty($row)){
?>
<table class="table table-bordered table-striped" id="datatable-editable">
<thead>
<tr>
<th><center>Add</center></th>
<th><center>Update</center></th>
<th><center>Delete</center></th>
<th><center>View</center></th>
</tr>
</thead>
<tbody>
<tr>
<?php $all_permissions = $permission->allPermissions();
while ($row=mysqli_fetch_assoc($all_permissions)) {
$perm_id = $row['perm_id'];
$check_permission = $permission->checkPermission($role_id,$perm_id);
while ($row=mysqli_fetch_assoc($check_permission)){
?>
<td><center><input type="checkbox" perm_id="<?php echo $row['perm_id']?>" value="<?php echo $row['permission']?>"> <?php echo $row['permission']?>
</center>
</td>
<?php
}} ?>
</tr>
<tr>
<?php foreach ($row as $val) {?>
<td>
<?php if ($val['permission'] == 'add' || $val['permission'] == 'update' || $val['permission'] == 'delete' || $val['permission'] == 'view'){ ?>
<input type="checkbox" checked="checked" value="<?php echo $val['id']?>">
<?php } else { ?> <input type="checkbox" value="<?php echo $val['id']?>" > <?php }?>
</td>
<?php } ?>
<!-- foreach ($value as $key => $val) {
// echo $key . ' => ' . $val." / ";
echo $key['prem'];
} -->
<!-- <td>
<?php if (in_array('add', $row)){ ?>
<input type="checkbox" checked="checked" value="<?php echo $id?>">
<?php } else { ?> <input type="checkbox" > <?php }?>
</td>
<td>
<?php if (in_array('update', $row)){ ?>
<input type="checkbox" checked="checked">
<?php } else { ?> <input type="checkbox" > <?php }?>
</td>
<td>
<?php if (in_array('delete', $row)){ ?>
<input type="checkbox" checked="checked">
<?php } else { ?> <input type="checkbox" > <?php }?>
</td>
<td>
<?php if (in_array('view', $row)){ ?>
<input type="checkbox" checked="checked">
<?php } else { ?> <input type="checkbox" > <?php }?>
</td> -->
</tr>
</tbody>
</table>
allPermissions()
public function allPermissions()
{
$query="SELECT * from permission where status = 1";
$conn=$this->Connection();
$result = mysqli_query($conn,$query);
$num_rows = mysqli_num_rows($result);
if ($num_rows>0) {
return $result;
}
}
chechkPermission()
public function checkPermission($role_id,$perm_id)
{
$query = "select * from role_perm rp where role_id = '$role_id' and perm_id = '$perm_id' ";
$conn=$this->Connection();
$result = mysqli_query($conn,$query);
$num_rows = mysqli_num_rows($result);
if ($num_rows>0) {
return $result;
}
}
its been three(now) days i'm stuck here, please help. and sorry for my bad english
Table Structure
This is how i want it
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…