I am trying to create a searching module with PHP 7, MySQL and Bootstrap. The only propblem is that if there is more domain for one role, the role is shown twice with the 2 different domain.
This is the popup window Popup window
This is the 3 table: Tables
I was trying to select the multiple datas from the database and add it to an array, but I am new in PHP and MySQL. This is the PHP code:
$output = '';  
    $sql="SELECT * FROM (SELECT role.role_id AS roleID, role.role_name AS roleNAME, domain.domain_name AS domainNAME
          FROM role 
          LEFT OUTER JOIN role_domain ON role.role_id=role_domain.role_id 
          LEFT OUTER JOIN domain ON domain.domain_id=role_domain.domain_id
          UNION 
          SELECT role.role_id AS roleID, role.role_name AS roleNAME, domain.domain_name AS domainNAME
          FROM role_domain
          RIGHT OUTER JOIN domain ON domain.domain_id=role_domain.domain_id
          RIGHT OUTER JOIN role ON role.role_id=role_domain.role_id) AS U
          WHERE U.roleID='".$_POST["szerep_id"]."'";
    $result = mysqli_query($conn,$sql);
    // A query that stores the multiple roles
    $query="SELECT role.role_name AS roleName, COUNT(role_domain.role_id) as role_count FROM role
            LEFT OUTER JOIN role_domain ON role.role_id = role_domain.role_id
            GROUP BY role_domain.role_id
            HAVING role_count > 1";
    $result1= mysqli_query($conn, $query);
    // Put the multiple roles to an array
    while($row=mysqli_fetch_array($result1))
        {
            $inspector[]=$row["roleName"];
        }
    // Create the table
    $output .= '  
    <div class="table-responsive">  
        <table class="table table-bordered">'; 
    // If the query has an error, it writes the error
    if($result===false)
    {
        die(print_r(mysqli_error($conn), true));
    }
    // Fill up the Popup Window with the information provided
    while($row=mysqli_fetch_array($result))   
    { 
            $output .= '  
            <tr>  
                 <td><label><b>Role name:</b></label></td>  
                 <td>'.$row["roleNAME"].'</td>  
            </tr>  
            <tr>  
                 <td><label><b>Domain:</b></label></td>  
                 <td>'.$row["domainNAME"].'</td>  
            </tr>
        ';
    }  
    $output .= "</table></div>"; 
    echo $output; 
    // Frees all resources for the specified statement
    $stmt=$conn->prepare($sql);
    mysqli_stmt_free_result($stmt);
}     
}
else
{
    echo "Connection could not be established.<br />";
    die(print_r(mysqli_error($conn), true));
}
Thanks for the help!
 
    