I have two(2) tables tblPermission and tblSubPermission which holds the permissions of the user. I wanted to create an interface like this
the problem is I am stuck with my reference code (please see reference code below). Like in the image the title of each column should be the main permissions (tblPermission
) and the check boxes are the sub permissions(tblSubPermission
).
Here is my database structure:
tblPermission (
PermissionID NVARCHAR
PremissionDesc NVARCHAR
)
tblSubPermission (
SubPermissionID NVARCHAR
PermissionID NVARCHAR
SubPremissionDesc NVARCHAR
)
Here is my reference code from my previous project that generates check boxes and arranged them by columns. See this as example
The checkbox should be organized with the main permission.
$counter = 0;
$column = '';
if(!empty($righttype)){
$sql = $conn->prepare('SELECT RightID, RightDescription FROM tblRight WHERE RightType = :righttype ORDER BY LENGTH(RightID), RightID');
$sql->bindValue(':righttype', $righttype);
}
else{
$sql = $conn->prepare('SELECT RightID, RightDescription FROM tblRight ORDER BY LENGTH(RightID), RightID');
}
if($sql->execute()){
$count = $sql->rowCount();
$fetchall = $sql->fetchAll();
$range = range(1, $count);
if(count($range) > 0){
$divideCount = ceil(count($range)/2);
$results = array_chunk($fetchall ,$divideCount);
foreach($results as $result){
$column .= '<div class="col-lg-6">';
foreach($result as $fetchall){
$counter++;
$rightid = $fetchall['RightID'];
$rightdesc = $fetchall['RightDescription'];
$class = "right";
$column .= '<div class="col-lg-auto">
<div class="custom-control custom-checkbox mb-3">
<input type="checkbox" class="custom-control-input right-checkbox '. $class .'" id="'. $rightid .'" value="'. $rightid .'">
<label class="custom-control-label" for="'. $rightid .'">'. $rightdesc .'</label>
</div>
</div>';
}
$column .= '</div>';
}
return $column;
}
}
else{
return $sql->errorInfo();
}