I am trying to give role-based access in my script. Here is the example of my code and tables
I want to display the pages which the user has access in a checkbox format. I tried to like this
$sql = "SELECT p.page_id AS pid,
p.page,
p.link,
ra.pages AS rpage
FROM pages p
INNER JOIN role_access ra
WHERE p.page_id IN (ra.pages) AND ra.role=1";
$query = mysqli_query($con, $sql) or die(mysqli_error($con));
$checked_arr = array();
while($row = mysqli_fetch_array($query)) {
$checked_arr = explode(",",$row['rpage']);
foreach ($checked_arr as $page) {
echo "<br/><input type='checkbox' name=\"pages[]\" value='$page' />$page<br>";
}
for var_dump($row['page'])
displays like this string 'New' (length=3)
only one page is is getting displayed.
It gives me checkbox with page_id but I want to display p.page value in-front of each checkbox. how to do it?
Here is my table structure.
Pages table
page_id | page | link
1 | New | new.php
2 | Edit | edit.php
3 | Details | details.php
4 | Report | export.php
role table
role_id | role_name
1 | Admin
2 | User1
role_access table
id | pages | role
1 | 1,2,3,4 | 1
2 | 3,4 | 2