Tenho as seguintes tabelas : permissoes_users
- id_user
- id_permissao
permissoes - id - permissao
Tenho uma variavel da sessao onde tenho o id di user , preciso fazer uma busca na tabela pelo id e as que tiverem o id do usuario exibir o nome da permissao... Como posso fazer?
Erro testando a primeira resposta:
Notice: Undefined index: permissao in /Applications/XAMPP/xamppfiles/htdocs/DEV WEB/projetoFinalBD/permissao.php on line 51
Notice: Undefined index: permissao in /Applications/XAMPP/xamppfiles/htdocs/DEV WEB/projetoFinalBD/permissao.php on line 51
Notice: Undefined index: permissao in /Applications/XAMPP/xamppfiles/htdocs/DEV WEB/projetoFinalBD/permissao.php on line 51
Notice: Undefined index: permissao in /Applications/XAMPP/xamppfiles/htdocs/DEV WEB/projetoFinalBD/permissao.php on line 51
Notice: Undefined index: permissao in /Applications/XAMPP/xamppfiles/htdocs/DEV WEB/projetoFinalBD/permissao.php on line 51
Notice: Undefined index: permissao in /Applications/XAMPP/xamppfiles/htdocs/DEV WEB/projetoFinalBD/permissao.php on line 51
Notice: Undefined index: permissao in /Applications/XAMPP/xamppfiles/htdocs/DEV WEB/projetoFinalBD/permissao.php on line 51
Notice: Undefined index: permissao in /Applications/XAMPP/xamppfiles/htdocs/DEV WEB/projetoFinalBD/permissao.php on line 51
Notice: Undefined index: permissao in /Applications/XAMPP/xamppfiles/htdocs/DEV WEB/projetoFinalBD/permissao.php on line 51
Notice: Undefined index: permissao in /Applications/XAMPP/xamppfiles/htdocs/DEV WEB/projetoFinalBD/permissao.php on line 51
Código completo :
<body>
<?php
$id_user = $_GET['id_user'];
function user_info_gamb ($id_user) {
$sql = mysql_query("SELECT * FROM usuarios WHERE id_user = '$id_user'");
return mysql_fetch_assoc($sql);
}
$nome = user_info_gamb($id_user);
//$permissao_pg = 1; include('funcoes/restringirpg.php');
?>
<div id="topo">
<?php echo "Bem - Vindo " . $nome["nome"]; include('funcoes/menu.php');?>
</div>
<div id="conteudo">
<table class="table-auto table-striped text-center" width="auto" border="0" align="center" >
<tr>
<td><strong>PERMISSÕES</strong></td>
</tr>
<?php
function permissao_info ($id_permissao) {
$sql = mysql_query("SELECT * FROM permissoes WHERE id = '$id_permissao'");
return mysql_fetch_assoc($sql);
}
$aux = 0;
$permissoes = mysql_query(" SELECT PU.ID_USER, P.PERMISSAO FROM PERMISSOES_USERS PU INNER JOIN PERMISSOES P ON PU.ID_PERMISSAO = P.ID ");
for ($i=0; $row=mysql_fetch_assoc($permissoes); $i++){$permissao = $row["permissao"];
echo "
<tr>
<td>$permissao</td>
</tr>
";
}
?>
</table>